Controller validation in Cakephp -


i wish validate in controller in cakephp. though validations working in models instead of model wish validate in controller well.

what did validate in contrller.

  $validates = array('email' => array(                     'required' => array(                         'rule' => array('notempty'),                         'message' => 'a email required'                     ),                     'isunique' => array(                         'rule' => array('notempty'),                         'message' => 'this email registered'                     ),                     'email' => array(                         'rule' => array('email'),                         'message' => 'enter valid mail address'                     )             ));             if ($this->user->validates($validates)) {                 die("action can performed validated !! fields correct");             } else {                 die("action can't performed  !! fields in-correct");             } 

it end me in correct condition no matters if field correct or not. please help

setting $this->model->validates = $validates; work suggested in previous answer risk overwriting other validation rules may set in model. it's better add, modify , remove validation rules on fly such:

$this->model->validator()     ->add('email', 'required', array(         'rule' => array('notempty'),         'message' => 'a email required'     ))     ->add('email', 'isunique', array(         'rule' => array('notempty'),         'message' => 'this email registered'     ))     ->add('email', 'email', array(         'rule' => array('email'),         'message' => 'enter valid mail address'     )); 

i left array presented it, assume have wrong rule on isunique

you can read more binding rules here: http://book.cakephp.org/2.0/en/models/data-validation.html#dynamically-change-validation-rules


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -