Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Model/Table/UsersProfilesTable.php
- class UserProfilesTable extends Table{
- public function validationDefault(Validator $validator){
- $validator = new Validator();
- $validator
- ->notEmpty("first_name","First name cannot be empty.")
- ->requirePresence("first_name")
- .......
- ->notEmpty("email", "Email cannot be empty.")
- ->requirePresence("email")
- ->add( "email", "email",[
- "rule" => ["email", true],
- "message" => "Enter a valid e-mail."
- ]);
- return $validator;
- }
- public function buildRules(RulesChecker $rules){
- $rules->add($rules->isUnique(['email'], 'Email should be unique'));
- return $rules;
- }
- //UsersController.php
- $user = $this->Users->patchEntity($user, $this->request->data);
- if($this->Users->save($user)){
- // Success msg
- }
- if($user->errors()){
- // This shows all the error messages except the one specified in the buildRules for unique email.
- pr($user->errors());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement