验证Combobox CakePHP

时间:2015-06-06 01:25:28

标签: php mysql validation cakephp cakephp-2.3

您好我使用CakePHP 2.6.3,我对某些型号的验证有问题。

我使用相同的信息填充两个不同的组合框,如何验证插入时它们不具有相同的值。

提前致谢。

编辑:

class Requisitoscurso extends AppModel {


public $validate = array( 
        'requisito' => array(
        'required' => array(
        'rule' => array('isUnique', array('requisito', 'cod_curso'), false), //sirve cuando se crea y no se pega con error, al editar deja repetir un requisito ya existente
        'message' => 'El requisito ya existe.')
        )
);

}

1 个答案:

答案 0 :(得分:1)

也许这样的自定义验证:

public $validate = array(
    'someField1' => array(
        'rule' => array('cantBeSame'),
        'message' => 'someField1 cant be the same as someField2.'
    ),
    'someField2' => array(
        'rule' => array('cantBeSame'),
        'message' => 'someField2 cant be the same as someField1.'
    )
)

public function cantBeSame(){

    return ( $this->data['Somemodel']['someField1'] != $this->data['Somemodel']['someField2'] );

}