How to use validation for unique value in cakephp

Cakephp

Posted on 10 Oct 15 by Vickey
  325



In some cases we use a unique value for a database table fields for example in case of sign up we use unique value for our email or username so that there should not be create
more then one user with the same username or email.Cakephp provides us a very eassy validation rule 'isUnique' this rule we use in our model

'email' => array(
 'required' => array(
     'rule' => array('notEmpty'),
     'message' => 'You must enter a username.'
 ),

 'unique' => array(
     'rule'    => 'isUnique',
     'message' => 'This email has already been taken.'
 )
),

 


If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com