當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。