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


PHP Validation::getDefaultMessage方法代码示例

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


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

示例1: testGetDefaultValidationMessageShouldReturnEmptyStringIfNoneIsSet

 public function testGetDefaultValidationMessageShouldReturnEmptyStringIfNoneIsSet()
 {
     $this->specify("getDefaultMessage() should return empty string if none is set", function () {
         $validation = new Validation();
         expect($validation->getDefaultMessage('_notexistentvalidationmessage_'))->isEmpty();
     });
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:7,代码来源:ValidationTest.php

示例2: validate

 /**
  * Executes the validation
  *
  * @package     base-app
  * @version     2.0
  *
  * @param object $validation Phalcon\Validation
  * @param string $field field name
  *
  * @return boolean
  *
  * @throws \Phalcon\Validation\Exception
  */
 public function validate(\Phalcon\Validation $validation, $field)
 {
     $value = $validation->getValue($field);
     $model = $this->getOption("model");
     $attribute = $this->getOption("attribute");
     if (empty($model)) {
         throw new \Phalcon\Validation\Exception("Model must be set");
     }
     if (empty($attribute)) {
         $attribute = $field;
     }
     if ($except = $this->getOption('except')) {
         $number = $model::count(array($attribute . "=:value: AND " . $attribute . "!= :except:", "bind" => array("value" => $value, 'except' => $except)));
     } else {
         $number = $model::count(array($attribute . "=:value:", "bind" => array("value" => $value)));
     }
     if ($number) {
         $label = $this->getOption("label");
         if (empty($label)) {
             $label = $validation->getLabel($field);
             if (empty($label)) {
                 $label = $field;
             }
         }
         $message = $this->getOption("message");
         $replacePairs = array(":field" => $label);
         if (empty($message)) {
             $message = $validation->getDefaultMessage("Uniqueness");
         }
         $validation->appendMessage(new \Phalcon\Validation\Message(strtr($message, $replacePairs), $field, "Uniqueness"));
         return false;
     }
     return true;
 }
开发者ID:al35mm,项目名称:Phalcon-Rocket,代码行数:47,代码来源:Uniqueness.php

示例3: validate

 /**
  * {@inheritdoc}
  *
  * @param Validation $validation
  * @param string     $attribute
  *
  * @return bool
  */
 public function validate(Validation $validation, $attribute)
 {
     $secret = $this->getOption('secret');
     $value = $validation->getValue($attribute);
     $request = $validation->getDI()->get('request');
     $remoteIp = $request->getClientAddress(false);
     if (!empty($value)) {
         $curl = curl_init(self::RECAPTCHA_URL);
         curl_setopt_array($curl, [CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => ['secret' => $secret, 'response' => $value, 'remoteip' => $remoteIp]]);
         $response = json_decode(curl_exec($curl), true);
         curl_close($curl);
     }
     if (empty($response['success'])) {
         $label = $this->getOption('label');
         if (empty($label)) {
             $label = $validation->getLabel($attribute);
         }
         $message = $this->getOption('message');
         $replacePairs = [':field', $label];
         if (empty($message) && !empty($response['error-codes'])) {
             $message = $this->messages[$response['error-codes']];
         }
         if (empty($message)) {
             $message = $validation->getDefaultMessage('ReCaptcha');
         }
         $validation->appendMessage(new Message(strtr($message, $replacePairs), $attribute, 'ReCaptcha'));
         return false;
     }
     return true;
 }
开发者ID:phalcon,项目名称:incubator,代码行数:38,代码来源:ReCaptcha.php


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