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


PHP Validation::validate方法代码示例

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


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

示例1: testInValid

 public function testInValid()
 {
     $array = ['ids' => ['foo@foo.ru', 'bar@bar.ru', 1234]];
     $this->validation->add('ids', $this->testable);
     $messages = $this->validation->validate($array);
     $this->assertEquals(1, count($messages));
 }
开发者ID:kachit,项目名称:phalcon-lib,代码行数:7,代码来源:ArrayElementsTest.php

示例2: validation

 public function validation()
 {
     $validator = new Validation();
     $validator->add('creeA', new PresenceOfValidator(array('message' => "La date de création est nécessaire")));
     $validator->add('courrierElectronique', new EmailValidator(array('field' => '', 'message' => 'Le courrier électronique est invalide')));
     $validator->add('statut', new ExclusionInValidator(array('domain' => array('X', 'Z'), 'message' => 'L\'état ne doit être "X" ou "Z"')));
     $validator->add('statut', new InclusionInValidator(array('domain' => array('P', 'I', 'w'), 'message' => 'L\'état doit être "P", "I" ou "w"')));
     $validator->add('courrierElectronique', new UniquenessValidator(array('message' => 'Le courrier électronique doit être unique', 'model' => $this)));
     $validator->validate('statut', new RegexValidator(array('pattern' => '/[A-Z]/', 'message' => "L'état ne correspond pas à l'expression régulière")));
     $validator->validate('courrierElectronique', new StringLengthValidator(array('min' => '7', 'max' => '50', 'messageMinimum' => "Le courrier électronique est trop court", 'messageMaximum' => "Le courrier électronique est trop long")));
     return $this->validate($validator);
 }
开发者ID:Jurigag,项目名称:cphalcon,代码行数:12,代码来源:Abonnes.php

示例3: testCustomMessage

 public function testCustomMessage()
 {
     $this->specify('Test Email validator works with a custom message.', function () {
         $validation = new Validation();
         $validation->add('email', new Email(['message' => 'The email is not valid']));
         $messages = $validation->validate([]);
         $expectedMessages = Validation\Message\Group::__set_state(['_messages' => [0 => Validation\Message::__set_state(['_type' => 'Email', '_message' => 'The email is not valid', '_field' => 'email', '_code' => '0'])]]);
         $this->assertEquals($expectedMessages, $messages);
         $messages = $validation->validate(['email' => 'x=1']);
         expect($expectedMessages)->equals($messages);
         $messages = $validation->validate(['email' => 'x.x@hotmail.com']);
         expect($messages)->count(0);
     });
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:14,代码来源:EmailTest.php

示例4: testCustomMessage

 public function testCustomMessage()
 {
     $this->specify('Test URL validator works with a custom message.', function () {
         $validation = new Validation();
         $validation->add('url', new Validation\Validator\Url(['message' => 'The url is not valid']));
         $messages = $validation->validate([]);
         $expectedMessages = Validation\Message\Group::__set_state(['_messages' => [0 => Validation\Message::__set_state(['_type' => 'Url', '_message' => 'The url is not valid', '_field' => 'url', '_code' => '0'])]]);
         expect($expectedMessages)->equals($messages);
         $messages = $validation->validate(['url' => 'x=1']);
         expect($expectedMessages)->equals($messages);
         $messages = $validation->validate(['url' => 'http://phalconphp.com']);
         expect($messages)->count(0);
     });
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:14,代码来源:UrlTest.php

示例5: testCustomMessage

 public function testCustomMessage()
 {
     $this->specify('Test Between validator works with a custom message.', function () {
         $validation = new Validation();
         $validation->add('price', new Between(['minimum' => 1, 'maximum' => 3, 'message' => 'The price must be between 1 and 3']));
         $messages = $validation->validate(['price' => 5]);
         $expectedMessages = Validation\Message\Group::__set_state(['_messages' => [0 => Validation\Message::__set_state(['_type' => 'Between', '_message' => 'The price must be between 1 and 3', '_field' => 'price', '_code' => '0'])]]);
         $this->assertEquals($expectedMessages, $messages);
         $messages = $validation->validate([]);
         expect($expectedMessages)->equals($messages);
         $messages = $validation->validate(['price' => 2]);
         expect($messages)->count(0);
     });
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:14,代码来源:BetweenTest.php

示例6: validate

 public function validate(array $data)
 {
     $messages = parent::validate($data);
     if ($messages->count() > 0) {
         throw new ValidationException($messages);
     }
 }
开发者ID:bilna-dev,项目名称:monitoring-tools,代码行数:7,代码来源:HostValidation.php

示例7: createAction

 public function createAction()
 {
     $response = new Response();
     $response->setHeader('Content-Type', 'application/json');
     if ($this->request->isPost()) {
         $validation = new Validation();
         $validation->add('profilesId', new PresenceOf(array('message' => '请选择一个角色类型')));
         $messages = $validation->validate($_POST);
         $datas = array();
         if (count($messages)) {
             foreach ($messages as $message) {
                 $datas[] = $message->getMessage();
             }
             $response->setJsonContent(array('status' => 'error', 'messages' => $datas));
         } else {
             $user = new Users();
             $user->assign(array('name' => $this->request->getPost('name', 'striptags'), 'email' => $this->request->getPost('email', 'email'), 'profilesId' => $this->request->getPost('profilesId', 'int')));
             if (!$user->save()) {
                 foreach ($user->getMessages() as $message) {
                     $datas[] = $message->getMessage();
                 }
                 $response->setJsonContent(array('status' => 'error', 'messages' => $datas));
             } else {
                 $response->setJsonContent(array('status' => 'success', 'messages' => '用户添加成功'));
             }
         }
     }
     return $response;
 }
开发者ID:robinxiong,项目名称:cmsdb,代码行数:29,代码来源:UsersController.php

示例8: signup

 public function signup($data)
 {
     foreach ($data as $k => $v) {
         $this->{$k} = $v;
     }
     $this->confirm = 1;
     $validation = new Validation();
     $validation->add('email', new Validation\Validator\Email(array('message' => 'Указан не действительный E-mail')));
     $validation->add('email', new \App\Library\Validators\Uniqueness(array("model" => 'App\\Models\\Users', "message" => "Такой E-mail уже используется.")));
     $validation->add('fname', new Validation\Validator\PresenceOf(array('message' => 'Поле "Имя" должно быть заполнено')));
     $validation->add('fname', new Validation\Validator\StringLength(array("max" => 40, 'messageMaximum' => 'Длина текста в поле "' . $this->getLabel('fname') . '" должна быть не более 40 символов')));
     $validation->add('lname', new Validation\Validator\StringLength(array("max" => 40, 'messageMaximum' => 'Длина текста в поле "' . $this->getLabel('lname') . '" должна быть не более 40 символов')));
     $validation->add('thname', new Validation\Validator\StringLength(array("max" => 40, 'messageMaximum' => 'Длина текста в поле "' . $this->getLabel('thname') . '" должна быть не более 40 символов')));
     $validation->add('password', new Validation\Validator\PresenceOf(array('message' => 'Пароль должен быть указан')));
     $validation->add('password', new Validation\Validator\Confirmation(array('with' => 'password_confirm', 'message' => '"Пароль" и "Повтор пароля" должны совпадать')));
     $messages = $validation->validate($data);
     if (count($messages)) {
         return $validation->getMessages();
     } else {
         if ($this->create() === true) {
             return true;
         } else {
             return $this->getMessages();
         }
     }
 }
开发者ID:atnartur,项目名称:SimpleBannerRotator,代码行数:26,代码来源:Users.php

示例9: indexAction

 /**
  * User login
  */
 public function indexAction()
 {
     //User has login yet
     if ($this->_user) {
         $this->session->remove('auth');
         unset($_SESSION);
     }
     $this->_addSocialLogin();
     //Regular login
     if ($this->request->isPost()) {
         $validation = new Validation();
         $validation->add('email', new Email());
         $messages = $validation->validate($this->request->getPost());
         if (count($messages)) {
             foreach ($messages as $message) {
                 $this->flashSession->error($message);
             }
             $this->response->redirect('/user/login/');
             return;
         }
         $email = strtolower($this->request->getPost('email', 'email'));
         $password = $this->request->getPost('password', 'string');
         if (Users::login($email, $password)) {
             $user = Users::getCurrentUser();
             $this->flashSession->success('Hi, ' . $user['full_name']);
             $this->response->redirect('/');
         } else {
             $this->flashSession->error('User or password not match!');
             $this->response->redirect('/user/login/');
         }
     }
 }
开发者ID:kimthangatm,项目名称:zcms,代码行数:35,代码来源:LoginController.php

示例10: indexAction

 /**
  * Login Action
  */
 public function indexAction()
 {
     //User has login yet
     if ($this->_user) {
         $this->session->remove('auth');
         unset($_SESSION);
     }
     //Regular login
     if ($this->request->isPost()) {
         $validation = new Validation();
         $validation->add('email', new Email());
         $messages = $validation->validate($this->request->getPost());
         if (count($messages)) {
             foreach ($messages as $message) {
                 $this->flashSession->error($message);
             }
             return $this->response->redirect('/admin/user/login/');
         }
         $email = strtolower($this->request->getPost('email', 'email'));
         $password = $this->request->getPost('password', 'string');
         if (Users::login($email, $password)) {
             $this->response->redirect('/admin/');
         } else {
             $this->flashSession->error('m_user_message_login__user_or_password_do_not_match');
             return $this->response->redirect('/admin/user/login/');
         }
     }
     return null;
 }
开发者ID:kimthangatm,项目名称:zcms,代码行数:32,代码来源:LoginController.php

示例11: testMultipleField

 /**
  * Tests alnum validator with multiple field
  *
  * @author Wojciech Ślawski <jurigag@gmail.com>
  * @since  2016-06-05
  */
 public function testMultipleField()
 {
     $this->specify('Test alnum validator with multiple field.', function () {
         $validation = new Validation();
         $validationMessages = ['name' => 'Name must be alnum', 'type' => 'Type must be alnum'];
         $validation->add(['name', 'type'], new Alnum(['message' => $validationMessages]));
         $messages = $validation->validate(['name' => 'SomeValue123', 'type' => 'SomeValue123']);
         expect($messages->count())->equals(0);
         $messages = $validation->validate(['name' => 'SomeValue123!@#', 'type' => 'SomeValue123']);
         expect($messages->count())->equals(1);
         expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['name']);
         $messages = $validation->validate(['name' => 'SomeValue123!@#', 'type' => 'SomeValue123!@#']);
         expect($messages->count())->equals(2);
         expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['name']);
         expect($messages->offsetGet(1)->getMessage())->equals($validationMessages['type']);
     });
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:23,代码来源:AlnumTest.php

示例12: testMultipleField

 /**
  * Tests numericality validator with multiple field
  *
  * @author Wojciech Ślawski <jurigag@gmail.com>
  * @since  2016-06-05
  */
 public function testMultipleField()
 {
     $this->specify('Test numericality validator with multiple field', function () {
         $validation = new Validation();
         $validationMessages = ['amount' => 'Amount must be digit.', 'price' => 'Price must be digit.'];
         $validation->add(['amount', 'price'], new Numericality(['message' => $validationMessages]));
         $messages = $validation->validate(['amount' => 123, 'price' => 123]);
         expect($messages->count())->equals(0);
         $messages = $validation->validate(['amount' => '123abc', 'price' => 123]);
         expect($messages->count())->equals(1);
         expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['amount']);
         $messages = $validation->validate(['amount' => '123abc', 'price' => '123abc']);
         expect($messages->count())->equals(2);
         expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['amount']);
         expect($messages->offsetGet(1)->getMessage())->equals($validationMessages['price']);
     });
 }
开发者ID:mattvb91,项目名称:cphalcon,代码行数:23,代码来源:NumericalityTest.php

示例13: testMultipleField

 /**
  * Tests between validator with multiple field
  *
  * @author Wojciech Ślawski <jurigag@gmail.com>
  * @since  2016-06-05
  */
 public function testMultipleField()
 {
     $this->specify('Test between validator with multiple field.', function () {
         $validation = new Validation();
         $validationMessages = ['amount' => 'Amount must be between 0 and 999.', 'price' => 'Price must be between 0 and 999.'];
         $validation->add(['amount', 'price'], new Between(['minimum' => ['amount' => 0, 'price' => 0], 'maximum' => ['amount' => 999, 'price' => 999], 'message' => $validationMessages]));
         $messages = $validation->validate(['amount' => 100]);
         expect($messages->count())->equals(0);
         $messages = $validation->validate(['amount' => 1000, 'price' => 100]);
         expect($messages->count())->equals(1);
         expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['amount']);
         $messages = $validation->validate(['amount' => 1000, 'price' => 1000]);
         expect($messages->count())->equals(2);
         expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['amount']);
         expect($messages->offsetGet(1)->getMessage())->equals($validationMessages['price']);
     });
 }
开发者ID:mattvb91,项目名称:cphalcon,代码行数:23,代码来源:BetweenTest.php

示例14: testMultipleField

 /**
  * Tests url validator with multiple field
  *
  * @author Wojciech Ślawski <jurigag@gmail.com>
  * @since  2016-06-05
  */
 public function testMultipleField()
 {
     $this->specify('Test url validator with multiple field.', function () {
         $validation = new Validation();
         $validationMessages = ['url' => 'Url must be correct url.', 'anotherUrl' => 'AnotherUrl must be correct url.'];
         $validation->add(['url', 'anotherUrl'], new Validation\Validator\Url(['message' => $validationMessages]));
         $messages = $validation->validate(['url' => 'http://google.com', 'anotherUrl' => 'http://google.com']);
         expect($messages->count())->equals(0);
         $messages = $validation->validate(['url' => '://google.', 'anotherUrl' => 'http://google.com']);
         expect($messages->count())->equals(1);
         expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['url']);
         $messages = $validation->validate(['url' => '://google.', 'anotherUrl' => '://google.']);
         expect($messages->count())->equals(2);
         expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['url']);
         expect($messages->offsetGet(1)->getMessage())->equals($validationMessages['anotherUrl']);
     });
 }
开发者ID:mattvb91,项目名称:cphalcon,代码行数:23,代码来源:UrlTest.php

示例15: testMultipleField

 /**
  * Tests email validator with multiple field
  *
  * @author Wojciech Ślawski <jurigag@gmail.com>
  * @since  2016-06-05
  */
 public function testMultipleField()
 {
     $this->specify('Test email validator with multiple field.', function () {
         $validation = new Validation();
         $validationMessages = ['email' => 'Email must be correct email.', 'anotherEmail' => 'AnotherEmail must be correct email.'];
         $validation->add(['email', 'anotherEmail'], new Email(['message' => $validationMessages]));
         $messages = $validation->validate(['email' => 'test@somemail.com', 'anotherEmail' => 'test@somemail.com']);
         expect($messages->count())->equals(0);
         $messages = $validation->validate(['email' => 'rootlocalhost', 'anotherEmail' => 'test@somemail.com']);
         expect($messages->count())->equals(1);
         expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['email']);
         $messages = $validation->validate(['email' => 'rootlocalhost', 'anotherEmail' => 'rootlocalhost']);
         expect($messages->count())->equals(2);
         expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['email']);
         expect($messages->offsetGet(1)->getMessage())->equals($validationMessages['anotherEmail']);
     });
 }
开发者ID:mattvb91,项目名称:cphalcon,代码行数:23,代码来源:EmailTest.php


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