當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Model::getFirstError方法代碼示例

本文整理匯總了PHP中yii\base\Model::getFirstError方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model::getFirstError方法的具體用法?PHP Model::getFirstError怎麽用?PHP Model::getFirstError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\base\Model的用法示例。


在下文中一共展示了Model::getFirstError方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: error

 /**
  * Generates a tag that contains the first validation error of the specified model attribute.
  * Note that even if there is no validation error, this method will still return an empty error tag.
  * @param Model $model the model object
  * @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
  * about attribute expression.
  * @param array $options the tag options in terms of name-value pairs. The values will be HTML-encoded
  * using [[encode()]]. If a value is null, the corresponding attribute will not be rendered.
  *
  * The following options are specially handled:
  *
  * - tag: this specifies the tag name. If not set, "div" will be used.
  * - encode: boolean, if set to false then the error message won't be encoded.
  *
  * See [[renderTagAttributes()]] for details on how attributes are being rendered.
  *
  * @return string the generated label tag
  */
 public static function error($model, $attribute, $options = [])
 {
     $attribute = static::getAttributeName($attribute);
     $error = $model->getFirstError($attribute);
     $tag = isset($options['tag']) ? $options['tag'] : 'div';
     $encode = !isset($options['encode']) || $options['encode'] !== false;
     unset($options['tag'], $options['encode']);
     return Html::tag($tag, $encode ? Html::encode($error) : $error, $options);
 }
開發者ID:Kest007,項目名稱:yii2,代碼行數:27,代碼來源:BaseHtml.php

示例2: error

 /**
  * Generates a tag that contains the first validation error of the specified model attribute.
  * Note that even if there is no validation error, this method will still return an empty error tag.
  * @param Model $model the model object
  * @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
  * about attribute expression.
  * @param array $options the tag options in terms of name-value pairs. The values will be HTML-encoded
  * using [[encode()]]. If a value is null, the corresponding attribute will not be rendered.
  *
  * The following options are specially handled:
  *
  * - tag: this specifies the tag name. If not set, "div" will be used.
  *
  * See [[renderTagAttributes()]] for details on how attributes are being rendered.
  *
  * @return string the generated label tag
  */
 public static function error($model, $attribute, $options = [])
 {
     $attribute = static::getAttributeName($attribute);
     $error = $model->getFirstError($attribute);
     $tag = isset($options['tag']) ? $options['tag'] : 'div';
     unset($options['tag']);
     return Html::tag($tag, Html::encode($error), $options);
 }
開發者ID:sciurodont,項目名稱:yii2,代碼行數:25,代碼來源:BaseHtml.php

示例3: returnFileValidateError

 /**
  * Returns response for case when file was not saved.
  * @param \yii\base\Model $model the model that has been validated.
  * @param string $attribute the name of validated attribute.
  * @return array array of json response.
  */
 protected function returnFileValidateError($model, $attribute)
 {
     return ['success' => false, 'message' => $model->getFirstError($attribute)];
 }
開發者ID:alex-dwt,項目名稱:file,代碼行數:10,代碼來源:UploadAction.php

示例4: error

 /**
  * Generates a tag that contains the first validation error of the specified model attribute.
  * Note that even if there is no validation error, this method will still return an empty error tag.
  * @param Model $model the model object
  * @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
  * about attribute expression.
  * @param array $options the tag options in terms of name-value pairs. The values will be HTML-encoded
  * using [[encode()]]. If a value is null, the corresponding attribute will not be rendered.
  *
  * The following options are specially handled:
  *
  * - tag: this specifies the tag name. If not set, "div" will be used.
  *   See also [[tag()]].
  * - encode: boolean, if set to false then the error message won't be encoded.
  *
  * See [[renderTagAttributes()]] for details on how attributes are being rendered.
  *
  * @return string the generated label tag
  */
 public static function error($model, $attribute, $options = [])
 {
     $attribute = static::getAttributeName($attribute);
     $error = $model->getFirstError($attribute);
     $tag = ArrayHelper::remove($options, 'tag', 'div');
     $encode = ArrayHelper::remove($options, 'encode', true);
     return Html::tag($tag, $encode ? Html::encode($error) : $error, $options);
 }
開發者ID:voskobovich,項目名稱:yii2,代碼行數:27,代碼來源:BaseHtml.php

示例5: showErrors

 /**
  * Return errors as bulleted list for model
  *
  * @param Model $model
  *
  * @return string
  */
 public static function showErrors($model)
 {
     $errors = [];
     foreach ($model->getAttributes() as $attribute => $setting) {
         $error = $model->getFirstError($attribute);
         if (trim($error) != null) {
             $errors[] = $error;
         }
     }
     return '<ul><li>' . implode("</li>\n<li>", $errors) . '</li></ul>';
 }
開發者ID:communityii,項目名稱:yii2-user,代碼行數:18,代碼來源:Module.php


注:本文中的yii\base\Model::getFirstError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。