当前位置: 首页>>代码示例>>PHP>>正文


PHP Validator::errors方法代码示例

本文整理汇总了PHP中Cake\Validation\Validator::errors方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::errors方法的具体用法?PHP Validator::errors怎么用?PHP Validator::errors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Validation\Validator的用法示例。


在下文中一共展示了Validator::errors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testMinLength

 /**
  * test minLength validation.
  *
  * @return void
  */
 public function testMinLength()
 {
     $validator = new Validator();
     $validator->provider('purifier', 'App\\Model\\Validation\\PurifierValidator')->add('biography', 'minLength', ['rule' => ['purifierMinLength', 10], 'provider' => 'purifier', 'message' => 'You fail']);
     $expected = ['biography' => ['minLength' => 'You fail']];
     $this->assertEquals($expected, $validator->errors(['biography' => 'LessThan9']));
     $this->assertEmpty($validator->errors(['biography' => 'more than 10 characteres']));
 }
开发者ID:Adnan0703,项目名称:Xeta,代码行数:13,代码来源:PurifierValidatorTest.php

示例2: list_add

 /**
  * List add
  * 
  * @param controle_id 
  * @author Leonardo Cavalcante do Prado, Angelo Gustavo, Gabriel Rafal
  * @return void or, if a post method is called, the redirect action
  */
 public function list_add($controle_id = null, $separacao_id = null)
 {
     $query = $this->Amostrarepasse->find('all')->where(['fk_controle' => $controle_id]);
     $this->paginate = ['maxLimit' => 5];
     $this->set('amostras', $this->paginate($query));
     $this->set('controle_id', $controle_id);
     $this->set('separacao_id', $separacao_id);
     $amostrarepasse = $this->Amostrarepasse->newEntity();
     $validator = new Validator();
     $validator->add('n_amostra', 'custom', ['rule' => function ($num_amostra) {
         $query = $this->Amostrarepasse->find('All')->where(['n_amostra' => $num_amostra]);
         if ($query->isEmpty()) {
             return true;
         } else {
             return false;
         }
     }]);
     if ($this->request->is('post')) {
         $amostrarepasse = $this->Amostrarepasse->patchEntity($amostrarepasse, $this->request->data);
         $amostrarepasse->set(['fk_controle' => $controle_id]);
         $error = $validator->errors($amostrarepasse->toArray());
         if (empty($error)) {
             $this->Amostrarepasse->save($amostrarepasse);
             $this->Flash->success('O repasse da amostra foi salvo.');
             return $this->redirect(['action' => 'list_add', $controle_id, $separacao_id]);
         } else {
             $this->Flash->error('O repasse da amostra não pôde ser salvo, por favor, tente novamente.');
         }
     }
     $this->set(compact('amostrarepasse'));
     $this->set('_serialize', ['amostrarepasse']);
 }
开发者ID:JohnathanALves,项目名称:Final,代码行数:39,代码来源:AmostrarepasseController.php

示例3: add

 public function add()
 {
     /*
     		if($this->request->is('post')){
     			$person = $this->Persons->newEntity();
     			$person = $this->Persons->patchEntity($person, $this->request->data);
     			if($this->Persons->save($person)){
     				return $this->redirect(['action' => 'index']);
     			}
     			if ($person->errors()){
     				$this->Flash->error('please check entered values...');
     			}
     		}
     */
     $person = $this->Persons->newEntity();
     $this->set('person', $person);
     if ($this->request->is('post')) {
         $validator = new Validator();
         $validator->add('age', 'comparison', ['rule' => ['comparison', '>', 20]]);
         $errors = $validator->errors($this->request->data);
         if (!empty($errors)) {
             $this->Flash->error('comparison error');
         } else {
             $person = $this->Persons->patchEntity($person, $this->request->data);
             if ($this->Persons->save($person)) {
                 return $this->redirect(['action' => 'index']);
             }
         }
     }
 }
开发者ID:KimiyukiYamauchi,项目名称:phppro.2015,代码行数:30,代码来源:PersonsController.php

示例4: list_add

 /**
  * List add
  * 
  * @param separacoes_id 
  * @author Leonardo Cavalcante do Prado
  * @return void or, if a post method is called, the redirect action
  */
 public function list_add($separacoes_id = null)
 {
     $query = $this->Costagem->find('all')->where(['fk_separacoes' => $separacoes_id]);
     $this->paginate = ['maxLimit' => 5];
     $this->set('costagens', $this->paginate($query));
     $this->set('separacoes_id', $separacoes_id);
     $costagem = $this->Costagem->newEntity();
     $validator = new Validator();
     $validator->add('n_amostra', 'custom', ['rule' => function ($num_amostra) {
         $query = $this->Costagem->find('All')->where(['n_amostra' => $num_amostra]);
         if ($query->isEmpty()) {
             return true;
         } else {
             return false;
         }
     }]);
     if ($this->request->is('post')) {
         $costagem = $this->Costagem->patchEntity($costagem, $this->request->data);
         $costagem->set(['fk_separacoes' => $separacoes_id]);
         $errors = $validator->errors($costagem->toArray());
         if (empty($errors)) {
             $this->Costagem->save($costagem);
             $this->Flash->success('A contagem foi salva.');
             return $this->redirect(['action' => 'list_add', $separacoes_id]);
         } else {
             $this->Flash->error('A contagem não pôde ser salva, por favor, tente novamente.');
         }
     }
     $this->set(compact('costagem'));
     $this->set('_serialize', ['costagem']);
 }
开发者ID:JohnathanALves,项目名称:Final,代码行数:38,代码来源:CostagemController.php

示例5: validate

 /**
  * Validates the internal properties using a validator object and returns any
  * validation errors found.
  *
  * @param \Cake\Validation\Validator $validator The validator to use when validating the entity.
  * @return array
  */
 public function validate(Validator $validator)
 {
     $data = $this->_properties;
     $new = $this->isNew();
     $validator->provider('entity', $this);
     $this->errors($validator->errors($data, $new === null ? true : $new));
     return $this->_errors;
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:15,代码来源:EntityValidatorTrait.php

示例6: testMaxDimensionSuccess

 /**
  * test maxDimension with success validation.
  *
  * @return void
  */
 public function testMaxDimensionSuccess()
 {
     $file = ['name' => 'avatar.png', 'tmp_name' => TEST_WWW_ROOT . 'img/avatar.png', 'error' => UPLOAD_ERR_OK, 'type' => 'image/png', 'size' => 201];
     $expected = ['avatar_file' => ['maxDimension' => 'You fail']];
     $this->assertEquals($expected, $this->validator->errors(['avatar_file' => $file]));
     $validator = new Validator();
     $validator->provider('upload', 'App\\Model\\Validation\\UploadValidator')->add('avatar_file', 'maxDimension', ['rule' => ['maxDimension', 160, 160], 'provider' => 'upload', 'message' => 'You fail']);
     $this->assertEmpty($validator->errors(['avatar_file' => $file]));
 }
开发者ID:edukondaluetg,项目名称:Xeta,代码行数:14,代码来源:UploadValidatorTest.php

示例7: validateUser

 public function validateUser()
 {
     $this->_validateError = 'ok';
     $validator = new Validator();
     $validator->requirePresence('email')->add('email', 'validFormat', ['rule' => 'email', 'message' => 'E-mail must be valid'])->add('password', 'length', ['rule' => ['minLength', 6]])->requirePresence('name')->notEmpty('name', 'We need your name.')->requirePresence('username')->notEmpty('username', 'We need Your Username.')->add('username', 'length', ['rule' => ['minLength', 6]]);
     $errors = $validator->errors($this->_user);
     if (!empty($errors)) {
         $this->_validateError = $errors;
         return false;
     } else {
         return true;
     }
 }
开发者ID:raulsi,项目名称:CakePHP-ArangoDb,代码行数:13,代码来源:UserModel.php

示例8: index

 /**
  * Contact page.
  *
  * @return \Cake\Network\Response|void
  */
 public function index()
 {
     $contact = ['schema' => ['name' => ['type' => 'string', 'length' => 100], 'email' => ['type' => 'email', 'length' => 100], 'subject' => ['type' => 'string', 'length' => 255], 'message' => ['type' => 'string']], 'required' => ['name' => 1, 'email' => 1, 'message' => 1]];
     if ($this->request->is('post')) {
         $validator = new Validator();
         $validator->notEmpty('email', __('You need to put your E-mail.'))->add('email', 'validFormat', ['rule' => 'email', 'message' => __("You must specify a valid E-mail address.")])->notEmpty('name', __('You need to put your name.'))->notEmpty('message', __("You need to give a message."))->add('message', 'minLength', ['rule' => ['minLength', 10], 'message' => __("Your message can not contain less than {0} characters.", 10)]);
         $contact['errors'] = $validator->errors($this->request->data());
         if (empty($contact['errors'])) {
             $viewVars = ['ip' => $this->request->clientIp()];
             $viewVars = array_merge($this->request->data(), $viewVars);
             $this->getMailer('Contact')->send('contact', [$viewVars]);
             $this->Flash->success(__("Your message has been sent successfully, you will get a response shortly !"));
             return $this->redirect(['controller' => 'pages', 'action' => 'home']);
         }
     }
     $this->set(compact('contact'));
 }
开发者ID:Xety,项目名称:Xeta,代码行数:22,代码来源:ContactController.php

示例9: index

 /**
  * Contact page.
  *
  * @return \Cake\Network\Response|void
  */
 public function index()
 {
     $contact = ['schema' => ['name' => ['type' => 'string', 'length' => 100], 'email' => ['type' => 'string', 'length' => 100], 'subject' => ['type' => 'string', 'length' => 255], 'message' => ['type' => 'string']], 'required' => ['name' => 1, 'email' => 1, 'message' => 1]];
     if ($this->request->is('post')) {
         $validator = new Validator();
         $validator->notEmpty('email', __('You need to put your E-mail.'))->add('email', 'validFormat', ['rule' => 'email', 'message' => __("You must specify a valid E-mail address.")])->notEmpty('name', __('You need to put your name.'))->notEmpty('message', __("You need to give a message."))->add('message', 'minLength', ['rule' => ['minLength', 10], 'message' => __("Your message can not contain less than {0} characters.", 10)]);
         $contact['errors'] = $validator->errors($this->request->data());
         if (empty($contact['errors'])) {
             $viewVars = ['ip' => $this->request->clientIp()];
             $viewVars = array_merge($this->request->data(), $viewVars);
             $email = new Email();
             $email->profile('default')->template('contact')->emailFormat('html')->from(['contact@xeta.io' => 'Contact Form'])->to(Configure::read('Author.email'))->subject($viewVars['subject'] ? $viewVars['subject'] : 'Someone has contacted you')->viewVars($viewVars)->send();
             $this->Flash->success(__("Your message has been sent successfully, you will get a response shortly !"));
             return $this->redirect('/');
         }
     }
     $this->set(compact('contact'));
 }
开发者ID:Adnan0703,项目名称:Xeta,代码行数:23,代码来源:ContactController.php

示例10: edit

 public function edit($id = NULL, $slug = NULL)
 {
     //Post Types
     $this->loadModel('Post_Type');
     $post_type_ids = $this->Post_Type->find('list');
     $this->set(compact('post_type_ids'));
     $this->loadModel('Categories');
     $category = $this->Categories->get($id);
     $this->set('title_for_layout', 'Category : ' . $category->title);
     if (empty($category)) {
         throw new NotFoundException('Could not find that category.');
     } else {
         $this->set(compact('category'));
     }
     if ($this->request->is(['post', 'put'])) {
         //Validation
         $validator = new Validator();
         $validator->requirePresence('post_type_id')->notEmpty('post_type_id', 'A post type is required.')->requirePresence('title')->notEmpty('title', 'A title is required.');
         $errors_array = $validator->errors($this->request->data());
         $error_msg = [];
         foreach ($errors_array as $errors) {
             if (is_array($errors)) {
                 foreach ($errors as $error) {
                     $error_msg[] = $error;
                 }
             } else {
                 $error_msg[] = $errors;
             }
         }
         if (!empty($error_msg)) {
             $this->Flash->set('Please fix the following error(s): ' . implode('\\n \\r', $error_msg), ['element' => 'alert-box', 'params' => ['class' => 'danger']]);
             return $this->redirect(['action' => 'edit', $id]);
         }
         $category->slug = Text::slug(strtolower($this->request->data('title')));
         //Save
         $this->Categories->patchEntity($category, $this->request->data);
         if ($this->Categories->save($category)) {
             $this->Flash->set('The category has been updated.', ['element' => 'alert-box', 'params' => ['class' => 'success']]);
             return $this->redirect(['action' => 'edit', $id]);
         }
         $this->Flash->set('Unable to update category.', ['element' => 'alert-box', 'params' => ['class' => 'danger']]);
     }
 }
开发者ID:gwhitcher,项目名称:cakeblog,代码行数:43,代码来源:CategoriesController.php

示例11: test

 public function test()
 {
     if ($this->request->env('Shib-Session-ID') === null) {
         $this->Flash->warning('To test your attribute releases, you have to login first');
     }
     $this->loadModel('Releases');
     foreach ($this->Attributes->find('all') as $attribute) {
         unset($temp);
         unset($errors);
         $temp['validator'] = $attribute['validation'];
         $attribute['value'] = $this->request->env($attribute->name);
         $validated = 'N/A';
         if (!empty($attribute['validation'])) {
             $validator = new Validator();
             $validator->allowEmpty('value')->add('value', 'validFormat', ['rule' => array('custom', '/^(' . $attribute['validation'] . ')$/i'), 'message' => 'RegEx match fails.']);
             $errors = $validator->errors(array('value' => $attribute['value']));
             $validated = 'FAIL';
         }
         $temp['value'] = $attribute['value'];
         if (!empty($errors)) {
             $temp['errors'] = $errors['value'];
         }
         $attributes[$attribute['schema']][$attribute['name']] = $temp;
         if (!empty($attribute['value'])) {
             $persistentid_array = preg_split('/!/', $this->request->env('persistent-id'));
             $persistentid = end($persistentid_array);
             $attr_release = array('attribute_name' => $attribute['name'], 'idp' => $this->request->env('Shib-Identity-Provider'), 'persistentid' => $persistentid, 'validated' => $validated);
             $query = $this->Releases->find()->andWhere(['attribute_name' => $attribute['name'], 'idp' => $this->request->env('Shib-Identity-Provider'), 'persistentid' => $persistentid]);
             if ($query->isEmpty()) {
                 $release = $this->Releases->newEntity();
             } else {
                 $id = $query->first()->id;
                 $release = $this->Releases->get($id, ['contain' => []]);
             }
             $release = $this->Releases->patchEntity($release, $attr_release);
             $this->Releases->save($release);
         }
     }
     $this->set(compact('attributes'));
     $this->set('_serialize', ['attributes']);
 }
开发者ID:csc-it-center-for-science,项目名称:attribute-test-service,代码行数:41,代码来源:AttributesController.php

示例12: edit

 public function edit($id = NULL, $slug = NULL)
 {
     $this->loadModel('Navigation');
     //Get all nav items
     $parent_ids = $this->Navigation->find('list');
     $this->set(compact('parent_ids'));
     $navigation = $this->Navigation->get($id);
     $this->set('title_for_layout', 'Navigation : ' . $navigation->title);
     if (empty($navigation)) {
         throw new NotFoundException('Could not find that navigation item.');
     } else {
         $this->set(compact('navigation'));
     }
     if ($this->request->is(['post', 'put'])) {
         //Validation
         $validator = new Validator();
         $validator->requirePresence('title')->notEmpty('title', 'A title is required.');
         $errors_array = $validator->errors($this->request->data());
         $error_msg = [];
         foreach ($errors_array as $errors) {
             if (is_array($errors)) {
                 foreach ($errors as $error) {
                     $error_msg[] = $error;
                 }
             } else {
                 $error_msg[] = $errors;
             }
         }
         if (!empty($error_msg)) {
             $this->Flash->set('Please fix the following error(s): ' . implode('\\n \\r', $error_msg), ['element' => 'alert-box', 'params' => ['class' => 'danger']]);
             return $this->redirect(['action' => 'edit', $id]);
         }
         //Save
         $this->Navigation->patchEntity($navigation, $this->request->data);
         if ($this->Navigation->save($navigation)) {
             $this->Flash->set('The navigation item has been updated.', ['element' => 'alert-box', 'params' => ['class' => 'success']]);
             return $this->redirect(['action' => 'edit', $id]);
         }
         $this->Flash->set('Unable to update navigation item.', ['element' => 'alert-box', 'params' => ['class' => 'danger']]);
     }
 }
开发者ID:gwhitcher,项目名称:cakeblog,代码行数:41,代码来源:NavigationController.php

示例13: testEmail

 /**
  * Tests the email proxy method
  *
  * @return void
  */
 public function testEmail()
 {
     $validator = new Validator();
     $validator->email('username');
     $this->assertEmpty($validator->errors(['username' => 'test@example.com']));
     $this->assertNotEmpty($validator->errors(['username' => 'not an email']));
 }
开发者ID:jdaosavanh,项目名称:clickerwebapp,代码行数:12,代码来源:ValidatorTest.php

示例14: reset

 /**
  * Reset password
  *
  * @param null|string $key
  *
  * @return \Cake\Network\Response|void
  */
 public function reset($key = null)
 {
     $this->set('title', __('Reset Password'));
     /** @var $usersTable UsersTable */
     $usersTable = TableRegistry::get('Pie/Users.Users');
     /** @var $user User */
     $user = $usersTable->find()->where(['status' => 1])->matching('UserDetails', function (Query $query) use($key) {
         return $query->where(['key' => 'reset_key', 'value' => $key]);
     })->contain('UserDetails')->first();
     if (!$user || is_null($key)) {
         throw new NotFoundException();
     }
     if ($this->request->is(['post', 'put'])) {
         $validator = new Validator();
         $validator->add('new_password', ['minLengthPassword' => ['rule' => ['minLength', 8], 'message' => __d('users', 'Minimum length of password is 8 characters.')]])->add('confirm_password', ['equalToPassword' => ['rule' => function ($value, $context) {
             if ($value === $context['data']['new_password']) {
                 return true;
             } else {
                 return false;
             }
         }, 'message' => __d('users', 'Entered passwords do not match.')]]);
         $errors = $validator->errors($this->request->data, $user->isNew());
         $user->errors($errors);
         if (empty($errors)) {
             $user->set('password', PasswordHasherFactory::build(Configure::read('pie.users.passwordHasher'))->hash($this->request->data('new_password')));
             if ($usersTable->save($user)) {
                 /** @var $userDetailsTable UserDetailsTable */
                 $userDetailsTable = TableRegistry::get('Pie/Users.UserDetails');
                 $userDetailsTable->delete($user->getDetails()['reset_key']);
                 $this->Flash->set(__('Your password has been reset successfully.'), ['element' => 'success']);
                 return $this->redirect(['action' => 'login']);
             }
         }
         $this->Flash->set(__('An error occurred. Please try again.'), ['element' => 'error']);
     }
     $this->set(compact('user'));
 }
开发者ID:phpie,项目名称:users-plugin,代码行数:44,代码来源:UsersController.php

示例15: testHasAtMost

 /**
  * Tests the hasAtMost method
  *
  * @return void
  */
 public function testHasAtMost()
 {
     $validator = new Validator();
     $validator->hasAtMost('things', 3);
     $this->assertEmpty($validator->errors(['things' => [1, 2, 3]]));
     $this->assertEmpty($validator->errors(['things' => [1]]));
     $this->assertNotEmpty($validator->errors(['things' => [1, 2, 3, 4]]));
     $this->assertEmpty($validator->errors(['things' => ['_ids' => [1, 2, 3]]]));
     $this->assertEmpty($validator->errors(['things' => ['_ids' => [1, 2]]]));
     $this->assertNotEmpty($validator->errors(['things' => ['_ids' => [1, 2, 3, 4]]]));
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:16,代码来源:ValidatorTest.php


注:本文中的Cake\Validation\Validator::errors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。