cakephp isUnique for 2 fields?

后端 未结 6 1614
醉梦人生
醉梦人生 2020-12-05 16:36

I have a registration form in which users can fill in two email address (email1 & email2). Marketing\'s requirement is that they need to be unique (unique as in if we ha

6条回答
  •  -上瘾入骨i
    2020-12-05 17:37

    From cakePHP 2.0 documentation:

    You can validate that a set of fields are unique by providing multiple fields and set $or to false:

    public $validate = array(
        'email' => array(
            'rule' => array('isUnique', array('email', 'username'), false),
            'message' => 'This username & email combination has already been used.'
        )
    );
    

    Make sure to include the original field in the list of fields when making a unique rule across multiple fields.

    If a listed field isn’t included in the model data, then it’s treated as a null value. You may consider marking the listed fields as required.

提交回复
热议问题