cakephp:模型验证规则,表单字段===

cakephp:模型验证规则,表单字段===,php,validation,cakephp,field,models,Php,Validation,Cakephp,Field,Models,在研究了Miles Jones纸杯蛋糕论坛插件后,我有几个问题: 1) 每个字段(出现在模型的验证规则中)都必须是数据库表中的字段吗?我在cupcake论坛插件的用户模型中发现了以下验证规则。oldPassword和newPassword不是用户表中的字段。我很困惑,因为我认为我应该只为表的字段制定验证规则 public $validate = array( 'username' => array( 'isUnique' => array(

在研究了Miles Jones纸杯蛋糕论坛插件后,我有几个问题:

1) 每个字段(出现在模型的验证规则中)都必须是数据库表中的字段吗?我在cupcake论坛插件的用户模型中发现了以下验证规则。oldPassword和newPassword不是用户表中的字段。我很困惑,因为我认为我应该只为表的字段制定验证规则

public $validate = array(
    'username' => array(
        'isUnique' => array(
            'rule' => 'isUnique',
            'message' => 'That username has already been taken',
            'on' => 'create'
        ),
        'notEmpty' => array(
            'rule' => 'notEmpty',
            'message' => 'Please enter a username'
        )
    ),
    'password' => array(
        'rule' => 'notEmpty',
        'message' => 'Please enter a password'
    ),
    'oldPassword' => array(
        'rule' => array('isPassword'),
        'message' => 'The old password did not match'
    ),
    'newPassword' => array(
        'isMatch' => array(
            'rule' => array('isMatch', 'confirmPassword'),
            'message' => 'The passwords did not match'
        ),
        'custom' => array(
            'rule' => array('custom', '/^[-_a-zA-Z0-9]+$/'),
            'message' => 'Your password may only be alphanumeric'
        ),
        'between' => array(
            'rule' => array('between', 6, 20),
            'message' => 'Your password must be 6-20 characters in length'
        ),
        'notEmpty' => array(
            'rule' => 'notEmpty',
            'message' => 'Please enter a password'
        )
    ),
    'email' => array(
        'isUnique' => array(
            'rule' => 'isUnique',
            'message' => 'That email has already been taken',
            'on' => 'create'
        ),
        'email' => array(
            //'rule' => array('email', true),//boolean true as second parameter verifies that the host for the address is valid -- to be uncommented once website is uploaded
            'rule' => array('email'),
            'message' => 'Your email is invalid'
        ),
        'notEmpty' => array(
            'rule' => 'notEmpty',
            'message' => 'Your email is required'
        )
    )
);
2) 是否每个表单字段都必须是数据库表中的字段

例如,当我要求用户注册时,将有:用户名、电子邮件地址、密码和确认密码。但是确认密码字段不需要是表中的字段,对吗? 这是个好习惯吗

我在form_app_model.php中找到了以下isMatch函数:

/**
 * Validates two inputs against each other
 * @access public
 * @param array $data
 * @param string $confirmField
 * @return boolean
 */
public function isMatch($data, $confirmField) {
    $data = array_values($data);
    $var1 = $data[0];
    $var2 = (isset($this->data[$this->name][$confirmField])) ? $this->data[$this->name][$confirmField] : '';

    return ($var1 === $var2);
}
有人能告诉我上面代码的最后一行是什么吗


谢谢。

这意味着完全相等(没有类型转换)。例如:如果y=25,则y==25为真,y==25为真,但y==25为非真。

=
表示相等

=
表示相同


=
在此处阅读,否-不是验证中的每个字段都必须是真实的数据库字段。