本文整理匯總了PHP中Phalcon\Validation::add方法的典型用法代碼示例。如果您正苦於以下問題:PHP Validation::add方法的具體用法?PHP Validation::add怎麽用?PHP Validation::add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Phalcon\Validation
的用法示例。
在下文中一共展示了Validation::add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: validation
public function validation()
{
$validator = new Validation();
$validator->add('login', new UniquenessValidator(["model" => $this, "message" => $this->getDi()->get('helper')->translate("The Login must be unique")]));
$validator->add('email', new UniquenessValidator(["model" => $this, "message" => $this->getDi()->get('helper')->translate("The Email must be unique")]));
return $this->validate($validator);
}
示例2: 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));
}
示例3: validation
public function validation()
{
$validator = new Validation();
$validator->add('name', new PetnameValidator());
$validator->add('birthday', new DateValidator(['message' => '您填寫的動物生日的格式有誤']));
return $this->validate($validator);
}
示例4: validation
public function validation()
{
$validator = new Validation();
$validator->add('email', new EmailValidator(['model' => $this, 'message' => 'Sorry, The email was registered by another user']));
$validator->add('username', new UniquenessValidator(['model' => $this, 'message' => 'Sorry, That username is already taken']));
return $this->validate($validator);
}
示例5: validation
/**
* Validate user's email
* @return bool
*/
public function validation()
{
$validator = new Validation();
$validator->add('email', new Email(['message' => 'Invalid email supplied']));
$validator->add('email', new Uniqueness(array('message' => 'Sorry, The email has been used by another user')));
return $this->validate($validator);
}
示例6: validation
public function validation()
{
$validator = new Validation();
$validator->add('start_time', new DatetimeValidator('開始時間格式有誤'));
$validator->add('end_time', new DatetimeValidator('結束時間格式有誤'));
return $this->validate($validator);
}
示例7: validation
public function validation()
{
$validator = new Validation();
$validator->add('departure_address', new StringLength(['max' => 200, 'messageMaximum' => '出發位置的長度不能超過200字']));
$validator->add('remark', new StringLength(['max' => 400, 'messageMaximum' => '備注的長度不能超過400字']));
return $this->validate($validator);
}
示例8: testShouldValidateUsingDigitsInDecimalValidation
public function testShouldValidateUsingDigitsInDecimalValidation()
{
$validation = new Validation();
$validation->add('number1', new Decimal(['places' => 2, 'digits' => 2, 'label' => 'Magic number #1', 'message' => ':field must contain valid decimal value']));
$validation->add('number2', new Decimal(['places' => 2, 'digits' => 1, 'label' => 'Magic number #2', 'message' => ':field must contain valid decimal value']));
$validation->validate(['number1' => '9.99', 'number2' => '6.99']);
$messages = $validation->getMessages();
$this->assertEquals(1, $messages->count());
$this->assertEquals('Magic number #1 must contain valid decimal value', $messages[0]->getMessage());
$this->assertEquals('Decimal', $messages[0]->getType());
}
示例9: testShouldValidateCardNumberForModel
/**
* @dataProvider providerCards
* @param mixed $type
* @param mixed $cardnumber
* @param boolean $willReturn
*/
public function testShouldValidateCardNumberForModel($type, $cardnumber, $willReturn)
{
$validation = new Validation();
if ($type) {
$validation->add('creditcard', new CardNumber(['type' => $type]));
} else {
$validation->add('creditcard', new CardNumber());
}
$messages = $validation->validate(['creditcard' => $cardnumber]);
$this->assertNotEquals($willReturn, $messages->valid());
}
示例10: 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);
}
示例11: 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();
}
}
}
示例12: 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;
}
示例13: 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;
}
示例14: validation
private function validation(array $param)
{
$validation = new Validation();
$validation->add('module', new PresenceOf(['message' => 'O nome da aplicação é necessária.']));
$validation->add('module', new StringLength(['max' => 20, 'min' => 2, 'messageMaximum' => 'Nome da aplicação muito grande!', 'messageMinimum' => 'Nome da aplicação muito pequeno!']));
$validation->add('todo', new PresenceOf(['message' => 'O nome da atividade é necessário.']));
$validation->add('todo', new StringLength(['max' => 20, 'min' => 2, 'messageMaximum' => 'Nome da atividade muito grande!', 'messageMinimum' => 'Nome da atividade muito pequeno!']));
$validation->add('action', new PresenceOf(['message' => 'O nome da ação é necessária.']));
$validation->add('action', new StringLength(['max' => 20, 'min' => 2, 'messageMaximum' => 'Nome da ação muito grande!', 'messageMinimum' => 'Nome da ação muito pequeno!']));
$validation->validate($param);
if ($validation->getMessages()->count()) {
foreach ($validation->getMessages() as $message) {
throw new Phalcon\Mvc\Micro\Exception($message, 401);
}
}
}
示例15: validation
/**
* @param Validation $validator
* @return Validation
*/
protected function validation(Validation $validator)
{
if ($this->getEmail()) {
$validator->add('email', new Email(['message' => 'The e-mail is not valid']));
}
return $validator;
}