How to validate single field of a model in cakephp

馋奶兔 提交于 2019-12-23 18:14:52

问题


I have a model called User and its $validate has 39 field validations and working fine in UsersController. In another controller I need to use the same code and validate only a single field from controller. Can Someonce please help me with this?


回答1:


Relevant docs.

Use the fieldList option in the model's validates() method.

$this->ModelName->set($this->data);
if ($this->ModelName->validates(array('fieldList' => array('myField')))) {
    // If myField validated successfully...
}


来源:https://stackoverflow.com/questions/15679943/how-to-validate-single-field-of-a-model-in-cakephp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!