本文整理汇总了PHP中Phalcon\Validation::getMessages方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::getMessages方法的具体用法?PHP Validation::getMessages怎么用?PHP Validation::getMessages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Validation
的用法示例。
在下文中一共展示了Validation::getMessages方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMessages
/**
* Get error messages
*
* @return array
*/
public function getMessages()
{
$messages = [];
foreach ($this->validation->getMessages() as $messageObject) {
$messages[$messageObject->getField()][$messageObject->getType()] = $messageObject->getMessage();
}
return $messages;
}
示例2: 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();
}
}
}
示例3: getMessages
/**
* @author Adeyemi Olaoye <yemi@cottacush.com>
* @return mixed|string
*/
public function getMessages()
{
$messages = [];
foreach (parent::getMessages() as $message) {
$messages[] = $message->getMessage();
}
return $this->getSentenceFromArray($messages);
}
示例4: getMessages
public function getMessages()
{
$messages = [];
foreach (parent::getMessages() as $message) {
$messages[] = $message->getMessage();
}
return $messages;
}
示例5: 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());
}
示例6: login
/**
* login
* @param array $data
* @return bool
* @throws Exception
*/
public function login($data)
{
if (!is_array($data)) {
throw new Exception('Login data mas by an array');
}
$validation = new Validation();
$validation->add('email', new Email(['message' => 'Invalid email', 'required' => true]))->add('password', new StringLength(['max' => 255, 'min' => 4, 'message' => 'The password must be at least 4 characters', 'required' => true]));
$validation->validate($data);
$this->addMessages($validation->getMessages());
if (!empty($this->getMessages())) {
return false;
}
$this->setAttributes($data);
return $this->user()->login($this->email, $this->password);
}
示例7: beforeValidation
public function beforeValidation()
{
$validation = new Validation();
$validation->add('password', new Confirmation(array('message' => 'Password doesn\'t match confirmation', 'with' => 'retype_password')));
$validation->validate(['password' => $this->password, 'retype_password' => $this->retype_password]);
$this->addMessages($validation->getMessages());
if (!empty($this->getMessages())) {
return false;
}
if ($this->reg_date === null) {
$this->reg_date = $this->timeService()->currentDateTime();
}
if ($this->role === null) {
$this->role = self::ROLE_USER;
}
if ($this->status === null) {
$this->status = self::STATUS_NEW;
}
if ($this->rating === null) {
$this->rating = (int) $this->rating;
}
if ($this->password !== null) {
$this->password_hash = $this->createPasswordHash();
}
return parent::beforeValidation();
}
示例8: 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);
}
}
}
示例9: getMessages
/**
* @return array
*/
public function getMessages()
{
$this->validation->getMessages()->filter($this->field);
}
示例10: beforeSave
public function beforeSave($data = null)
{
if (!$this->isNew()) {
return true;
}
$validation = new Validation();
$validation->add('password', new Confirmation(array('message' => 'Password doesn\'t match confirmation', 'with' => 'retype_password')));
$validation->validate($data);
$this->addMessages($validation->getMessages());
if (!empty($this->getMessages())) {
return false;
}
if (!isset($data['reg_date'])) {
$data['reg_date'] = $this->timeService()->currentDateTime();
}
if (!isset($data['role'])) {
$data['role'] = self::ROLE_USER;
}
if (!isset($data['status'])) {
$data['status'] = self::STATUS_NEW;
}
if (!isset($data['rating'])) {
$data['rating'] = (int) $this->rating;
}
if (isset($data['password'])) {
$data['password_hash'] = $this->createPasswordHash($data['password'], $data['reg_date'], $data['email']);
}
return $data;
}