Kohana v3.1.0 ORM _ignored_columns-既然不见了,我该怎么办? [英] Kohana v3.1.0 ORM _ignored_columns -- now that it's gone, what should I do instead?

查看:66
本文介绍了Kohana v3.1.0 ORM _ignored_columns-既然不见了,我该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Kohana的ORM v3.1.0中,似乎已删除了_ignored_columns属性.

It seems that in v3.1.0 of Kohana's ORM that the _ignored_columns property has been removed.

处理数据库中没有的字段的推荐技术是什么?我现在遇到的情况是password_confirm,其中password是一个字段,但是我们要求用户输入两次密码.

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.

推荐答案

您可以传递一个额外的验证对象来保存,创建和更新.因此,您的示例如下所示:

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
 * @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);
}

请注意如何将密码验证传递到create方法中.

Notice how the password validation is passed into the create method.

$keys值指定应将哪些值保存到模型中. "password_confirm"不在该列表中,因此将被忽略.此功能也与安全性相关,您不希望用户在其POST请求中手动设置ID.

The $keys value specifies which values should be saved into the model. "password_confirm" was not in that list so it is ignored. This feature is security related too, you wouldn't want users manually setting the id in their POST request.

然后您可以通过调用create_user创建用户:

Then you can create a user by calling create_user:

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

这篇关于Kohana v3.1.0 ORM _ignored_columns-既然不见了,我该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆