问题
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