Kohana v3.1.0 ORM _ignored_columns - now that he is gone, what should I do instead?

It seems that in v3.1.0 ORA _ignored_columns , the _ignored_columns property _ignored_columns been removed.

What is the recommended method for working with fields that are not in the databases? The case I have now is password_confirm, where password is a field, but we require the user to enter their password twice.

+4
source share
1 answer

You can pass an additional validation object to save, create, and update. So your example would look like this:

 /** * Password validation for plain passwords. * * @param array $values * @return Validation */ public static function get_password_validation($values) { return Validation::factory($values) ->label('password', 'password') ->label('password_confirm', 'repeat password') ->rule('password', 'not_empty') ->rule('password', 'min_length', array(':value', 8)) ->rule('password_confirm', 'matches', array(':validation', ':field', 'password')); } /** * Create user account * * @param array $values * @param array $keys * @throws ORM_Validation_Exception */ public function create_user($values, $keys) { $external = Model_User::get_password_validation($values); $this->values($values, $keys); return $this->create($external); } 

Note how password verification is passed to the create method.

The value of $keys indicates which values ​​should be stored in the model. "password_confirm" was not in this list, so it is ignored. This feature is also related to security, you do not want users to manually set the identifier in their POST request.

You can then create the user by calling create_user :

 $user->create_user($_POST, array('username', 'email', 'password')); 
+4
source

Source: https://habr.com/ru/post/1339521/


All Articles