Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. // Model/Table/UsersProfilesTable.php
  2.  
  3. class UserProfilesTable extends Table{
  4.  
  5. public function validationDefault(Validator $validator){
  6.  
  7. $validator = new Validator();
  8.  
  9. $validator
  10. ->notEmpty("first_name","First name cannot be empty.")
  11. ->requirePresence("first_name")
  12. .......
  13. ->notEmpty("email", "Email cannot be empty.")
  14. ->requirePresence("email")
  15. ->add( "email", "email",[
  16. "rule" => ["email", true],
  17. "message" => "Enter a valid e-mail."
  18. ]);
  19.  
  20.  
  21.  
  22. return $validator;
  23. }
  24.  
  25. public function buildRules(RulesChecker $rules){
  26.  
  27. $rules->add($rules->isUnique(['email'], 'Email should be unique'));
  28.  
  29. return $rules;
  30. }
  31.  
  32. //UsersController.php
  33.  
  34. $user = $this->Users->patchEntity($user, $this->request->data);
  35.  
  36. if($this->Users->save($user)){
  37. // Success msg
  38. }
  39.  
  40. if($user->errors()){
  41. // This shows all the error messages except the one specified in the buildRules for unique email.
  42. pr($user->errors());
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement