kohana-3

How to apply the “matches” validation rule in Kohana 3.1?

南笙酒味 提交于 2019-12-22 12:27:22
问题 I need to know how to apply the "matches" validation rule in Kohana 3.1. I've tried the following rule in my model with no success: 'password_confirm' => array( array('matches', array(':validation', ':field', 'password')), ) But it always fails. I put a var_dump($array) in the first line of the Valid::matches() method. I paste it below: /** * Checks if a field matches the value of another field. * * @param array array of values * @param string field name * @param string field name to match *

Helping Kohana 3 ORM to speed up a little

半世苍凉 提交于 2019-12-22 09:42:30
问题 I noticed that Kohana 3 ORM runs a "SHOW FULL COLUMNS" for each of my models when I start using them: SHOW FULL COLUMNS FROM `mytable` This query might take a few clock cycles to execute (in the Kohana profiler it's actually the slowest of all queries ran in my current app). Is there a way to help Kohana 3 ORM to speed up by disabling this behaviour and explicitly define the columns in my models instead? 回答1: biakaveron answered my question with a comment so I can't except the correct answer.

Kohana v3.1.0 ORM _ignored_columns — now that it's gone, what should I do instead?

百般思念 提交于 2019-12-22 08:52:56
问题 It seems that in v3.1.0 of Kohana's ORM that the _ignored_columns property has been removed. What the is the recommended technique to dealing with fields that aren't in the databases? The case I have right now is password_confirm where password is a field, but we require the user to enter their password twice. 回答1: You can pass an extra validation object to save, create and update. So your example would look like: /** * Password validation for plain passwords. * * @param array $values *

Kohana 3 auth module, getting users with 'staff' or 'manager' role

▼魔方 西西 提交于 2019-12-22 06:37:06
问题 I'm learning the framework, and now building an application using it. I need to get all users that have 'user' or 'staff' role, but I couldn't find about it on the documentation. Help anyone? (I think it's more an ORM problem the the auth module) 回答1: I didn't find an easy way to do this using the ORM, but I have a workaround. This is my code for anyone who might encounter the same problem with me. // One for each role $staffs = ORM::factory('role', array('name' => 'staff'))->users->find_all(

Custom Exception Handling in Kohana3

亡梦爱人 提交于 2019-12-21 02:40:15
问题 I have a requirement to create custom exception for the exceptions generated by my app/module. I want to consolidate all the exception classes in one place and handle the exceptions in one place. I might have generic exceptions, like mentioned below, which I would like in one common place input invalid internal error (database errors, smtp errors, other failures) permission denied session error I might have specific exceptions, like mentioned below email not valid, etc. Specific exceptions

Kohana 3 get current controller/action/arguments

我是研究僧i 提交于 2019-12-20 10:11:15
问题 In Kohana 2 you could easily get that information like this: echo router::$controller; echo router::$method; echo router::$arguments[0-x]; Any idea how that works in Kohana 3? Thanks in advance! 回答1: From inside a controller: $this->request->controller $this->request->action $this->request->param('paramname') Unlike K2 arguments in K3 are accessed via kays which you define in your routes. Take for example this url: Route::set('default', '(<controller>(/<action>(/<id>)))') ->defaults(array(

Kohana 3.3 ORM _has_many _belongs_to

不问归期 提交于 2019-12-20 07:39:11
问题 I am trying to set up a product object in Kohana 3.3 using the built in ORM. I want it so that when I call: $p1 = ORM::factory('product') ->where('product_type', '=', '1') ->find_all(); it will create an object of this structure: Model_Product Object ( [_long_list_of_kohana_properties] => Array () [_object:protected] => Array ( [id] => 2 [product_type] => 1 ... [product_attributes] => Array (List of attributes) ) ) Currently, it produces this: Model_Product Object ( [_long_list_of_kohana

PHP shorthand syntax

穿精又带淫゛_ 提交于 2019-12-20 04:17:06
问题 I've just came across this on GitHub. ($config === NULL) and $config = Kohana::config('email'); Is that the equivalent of if ($config === NULL) { $config = Kohana::config('email'); } Is this commonplace? Would I expect other developers looking at my code if I used that first way to instantly know what it was doing? 回答1: Took me a second to get it, but that should actually work in just about every programming language. Because the "and" or "or" operators are lazily evaluated, if the statement

How to setup a custom 404 page for a Kohana v3 app

依然范特西╮ 提交于 2019-12-18 16:59:03
问题 How can this be done? I'm trying to do this for about half an hour and it's getting pretty annoying. You would this this should be an basic and easy thing to setup for a framework like this. I hope maybe there's an easy way i missed, because i'm starting to thing i should not chose this framework at all if such basic tings are so hard to setup. This is in my bootstrap.php file that should do the trick. if ( ! defined('SUPPRESS_REQUEST')) { /** * Execute the main request. A source of the URI

Kohana 3.1 - The system does not load email module

霸气de小男生 提交于 2019-12-13 20:08:28
问题 I have a problem using Kohana 3.1. I add the old banks kohana-email module but the result is a error like this: ErrorException [ Fatal Error ]: Class 'Email' not found My application bootstrap.php file is like this: Kohana::modules(array( 'user' => MODPATH.'user', // Useradmin module 'auth' => MODPATH.'auth', // Basic authentication // 'cache' => MODPATH.'cache', // Caching with multiple backends // 'codebench' => MODPATH.'codebench', // Benchmarking tool 'database' => MODPATH.'database', //