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


PHP Model::getAttributeLabel方法代码示例

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


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

示例1: run

 /**
  * @inheritdoc
  */
 public function run()
 {
     Asset::register($this->view);
     $inputId = Html::getInputId($this->model, $this->attribute);
     $field = $this->render('_field', ['fieldClass' => 'field-' . $inputId, 'inputId' => $inputId, 'inputName' => Html::getInputName($this->model, $this->attribute) . '[]', 'inputLabel' => $this->model->getAttributeLabel($this->attribute)]);
     $options = Json::htmlEncode(['field' => $field, 'firstAddTogglerText' => 'добавить свою категорию', 'addTogglerText' => 'добавить ещё', 'values' => $this->model->{$this->attribute}]);
     $this->view->registerJs('jQuery("#' . $this->id . '").kategoriiSlushatelejInputFields(' . $options . ');');
     return Html::tag('div', $this->renderFirstToggler(), ['id' => $this->id, 'class' => 'kategorii-slushatelej-input-fields']);
 }
开发者ID:tsyrya,项目名称:mybriop,代码行数:12,代码来源:KategoriiSlushatelejInputFields.php

示例2: prepareMessages

 /**
  * Applies the required formatting and params to messages.
  * @param Model $model
  * @param string $attribute
  * @return array Prepared messages
  */
 public function prepareMessages($model, $attribute)
 {
     $params = array_merge($this->messageParams(), ['attribute' => $model->getAttributeLabel($attribute)]);
     $messages = [];
     foreach ($this->messages() as $name => $message) {
         $messages[$name] = Yii::$app->getI18n()->format($message, $params, Yii::$app->language);
     }
     return $messages;
 }
开发者ID:undefinedstudio,项目名称:yii2-angular-form,代码行数:15,代码来源:AngularValidator.php

示例3: getAttributeLabel

 public function getAttributeLabel($attribute)
 {
     foreach ($this->models as $model) {
         if ($model->hasAttribute($attribute)) {
             return $model->getAttributeLabel($attribute);
         }
     }
     return parent::getAttributeLabel($attribute);
 }
开发者ID:yinheark,项目名称:yincart2,代码行数:9,代码来源:FormModel.php

示例4: errorsToString

 /**
  * Extracts Model errors from array and puts them into string
  * @param Model $model
  * @param boolean $html
  * @return string
  */
 public static function errorsToString($model, $html = true)
 {
     $result = '';
     $delimiter = $html ? "<br/>\n" : "\n";
     foreach ($model->errors as $attribute => $error) {
         $errors = implode(', ', $error);
         $result .= $model->getAttributeLabel($attribute) . ": {$errors}{$delimiter}";
     }
     return $result;
 }
开发者ID:sjoorm,项目名称:yii2-components,代码行数:16,代码来源:Misc.php

示例5: validateAttributes

 /**
  * Валидация атрибутов.
  *
  * На вход передается модель для валидации и массив значений для валидации.
  * Массив значений должен иметь следующий формат:
  * ```php
  * array(
  *     '<attribute1>' => array(
  *         array(
  *             'value' => <mixed>, // значение для валидации
  *             'isValid' => <boolean>, // true, если значение должно проходить валидацию
  *         ),
  *     ),
  * )
  * ```
  *
  * Проверяет, что атрибут либо должен проходить проверку валидации, либо не должен.
  *
  * @param Model $model проверяемая модель
  * @param array $attributes массив значений атрибутов для валидации
  */
 protected function validateAttributes(Model $model, $attributes)
 {
     foreach ($attributes as $attribute => $values) {
         $attributeTitle = $model->getAttributeLabel($attribute);
         foreach ($values as $v) {
             $value = $v['value'];
             $isValid = $v['isValid'];
             $model->{$attribute} = $value;
             if ($isValid) {
                 $message = $attributeTitle . ' validation error: ' . implode("\n", $model->getErrors($attribute));
                 $message .= "\nAsserting value: " . print_r($value, true);
                 $this->assertTrue($model->validate([$attribute]), $message);
             } else {
                 $message = $attributeTitle . ' must be invalid' . "\n";
                 $message .= 'Asserting value: ' . print_r($value, true);
                 $this->assertFalse($model->validate([$attribute]), $message);
             }
         }
     }
 }
开发者ID:internet-design,项目名称:yii2-svk-tests,代码行数:41,代码来源:ModelTestTrait.php

示例6: getClientOptions

 /**
  * Returns the client side validation options.
  * @param \yii\base\Model $model the model being validated
  * @param string $attribute the attribute name being validated
  * @return array the client side validation options
  */
 protected function getClientOptions($model, $attribute)
 {
     $label = $model->getAttributeLabel($attribute);
     $options = [];
     if ($this->message !== null) {
         $options['message'] = Yii::$app->getI18n()->format($this->message, ['attribute' => $label], Yii::$app->language);
     }
     $options['skipOnEmpty'] = $this->skipOnEmpty;
     if (!$this->skipOnEmpty) {
         $options['uploadRequired'] = Yii::$app->getI18n()->format($this->uploadRequired, ['attribute' => $label], Yii::$app->language);
     }
     if ($this->mimeTypes !== null) {
         $options['mimeTypes'] = $this->mimeTypes;
         $options['wrongMimeType'] = Yii::$app->getI18n()->format($this->wrongMimeType, ['attribute' => $label, 'mimeTypes' => join(', ', $this->mimeTypes)], Yii::$app->language);
     }
     if ($this->extensions !== null) {
         $options['extensions'] = $this->extensions;
         $options['wrongExtension'] = Yii::$app->getI18n()->format($this->wrongExtension, ['attribute' => $label, 'extensions' => join(', ', $this->extensions)], Yii::$app->language);
     }
     if ($this->minSize !== null) {
         $options['minSize'] = $this->minSize;
         $options['tooSmall'] = Yii::$app->getI18n()->format($this->tooSmall, ['attribute' => $label, 'limit' => $this->minSize], Yii::$app->language);
     }
     if ($this->maxSize !== null) {
         $options['maxSize'] = $this->maxSize;
         $options['tooBig'] = Yii::$app->getI18n()->format($this->tooBig, ['attribute' => $label, 'limit' => $this->maxSize], Yii::$app->language);
     }
     if ($this->maxFiles !== null) {
         $options['maxFiles'] = $this->maxFiles;
         $options['tooMany'] = Yii::$app->getI18n()->format($this->tooMany, ['attribute' => $label, 'limit' => $this->maxFiles], Yii::$app->language);
     }
     return $options;
 }
开发者ID:jenn0pal,项目名称:yii2,代码行数:39,代码来源:FileValidator.php

示例7: addComboNotUniqueError

 /**
  * Builds and adds [[comboNotUnique]] error message to the specified model attribute.
  * @param \yii\base\Model $model the data model.
  * @param string $attribute the name of the attribute.
  */
 private function addComboNotUniqueError($model, $attribute)
 {
     $attributeCombo = [];
     $valueCombo = [];
     foreach ($this->targetAttribute as $key => $value) {
         if (is_int($key)) {
             $attributeCombo[] = $model->getAttributeLabel($value);
             $valueCombo[] = '"' . $model->{$value} . '"';
         } else {
             $attributeCombo[] = $model->getAttributeLabel($key);
             $valueCombo[] = '"' . $model->{$key} . '"';
         }
     }
     $this->addError($model, $attribute, $this->message, ['attributes' => Inflector::sentence($attributeCombo), 'values' => implode('-', $valueCombo)]);
 }
开发者ID:yiisoft,项目名称:yii2,代码行数:20,代码来源:UniqueValidator.php

示例8: addError

 /**
  * Adds an error about the specified attribute to the model object.
  * This is a helper method that performs message selection and internationalization.
  * @param \yii\base\Model $object the data object being validated
  * @param string $attribute the attribute being validated
  * @param string $message the error message
  * @param array $params values for the placeholders in the error message
  */
 public function addError($object, $attribute, $message, $params = [])
 {
     $value = $object->{$attribute};
     $params['attribute'] = $object->getAttributeLabel($attribute);
     $params['value'] = is_array($value) ? 'array()' : $value;
     $object->addError($attribute, Yii::$app->getI18n()->format($message, $params, Yii::$app->language));
 }
开发者ID:pathman,项目名称:yii2comm,代码行数:15,代码来源:Validator.php

示例9: getAttributeLabel

 /**
  * Gets an attribute label
  *
  * @param string $attribute
  *
  * @return string
  */
 public function getAttributeLabel($attribute)
 {
     return parent::getAttributeLabel($attribute);
 }
开发者ID:nox-it,项目名称:yii2-nox-mvc,代码行数:11,代码来源:Model.php

示例10: getClientOptions

 /**
  * Returns the client side validation options.
  * @param \yii\base\Model $model the model being validated
  * @param string $attribute the attribute name being validated
  * @return array the client side validation options
  */
 protected function getClientOptions($model, $attribute)
 {
     $label = $model->getAttributeLabel($attribute);
     $format = function ($message, $label) {
         return Yii::$app->getI18n()->format($message, ['attribute' => $label], Yii::$app->language);
     };
     return ['skipOnEmpty' => $this->skipOnEmpty, 'typeAttribute' => Html::getInputId($model, $this->typeAttribute), 'messageLength' => $format($this->getAdapter($model)->messageLength, $label), 'messageChecksum' => $format($this->getAdapter($model)->messageChecksum, $label), 'messageCharacters' => $format($this->getAdapter($model)->messageCharacters, $label)];
 }
开发者ID:lembadm,项目名称:yii2-barcode-validator,代码行数:14,代码来源:BarcodeValidator.php

示例11: getClientOptions

 /**
  * Returns the client-side validation options.
  * @param \yii\base\Model $model the model being validated
  * @param string $attribute the attribute name being validated
  * @return array the client-side validation options
  */
 protected function getClientOptions($model, $attribute)
 {
     $label = $model->getAttributeLabel($attribute);
     $options = [];
     if ($this->message !== null) {
         $options['message'] = Yii::$app->getI18n()->format($this->message, ['attribute' => $label], Yii::$app->language);
     }
     $options['skipOnEmpty'] = $this->skipOnEmpty;
     if (!$this->skipOnEmpty) {
         $options['uploadRequired'] = Yii::$app->getI18n()->format($this->uploadRequired, ['attribute' => $label], Yii::$app->language);
     }
     if ($this->mimeTypes !== null) {
         $mimeTypes = [];
         foreach ($this->mimeTypes as $mimeType) {
             $mimeTypes[] = new JsExpression(Html::escapeJsRegularExpression($this->buildMimeTypeRegexp($mimeType)));
         }
         $options['mimeTypes'] = $mimeTypes;
         $options['wrongMimeType'] = Yii::$app->getI18n()->format($this->wrongMimeType, ['attribute' => $label, 'mimeTypes' => implode(', ', $this->mimeTypes)], Yii::$app->language);
     }
     if ($this->extensions !== null) {
         $options['extensions'] = $this->extensions;
         $options['wrongExtension'] = Yii::$app->getI18n()->format($this->wrongExtension, ['attribute' => $label, 'extensions' => implode(', ', $this->extensions)], Yii::$app->language);
     }
     if ($this->minSize !== null) {
         $options['minSize'] = $this->minSize;
         $options['tooSmall'] = Yii::$app->getI18n()->format($this->tooSmall, ['attribute' => $label, 'limit' => $this->minSize, 'formattedLimit' => Yii::$app->formatter->asShortSize($this->minSize)], Yii::$app->language);
     }
     if ($this->maxSize !== null) {
         $options['maxSize'] = $this->maxSize;
         $options['tooBig'] = Yii::$app->getI18n()->format($this->tooBig, ['attribute' => $label, 'limit' => $this->getSizeLimit(), 'formattedLimit' => Yii::$app->formatter->asShortSize($this->getSizeLimit())], Yii::$app->language);
     }
     if ($this->maxFiles !== null) {
         $options['maxFiles'] = $this->maxFiles;
         $options['tooMany'] = Yii::$app->getI18n()->format($this->tooMany, ['attribute' => $label, 'limit' => $this->maxFiles], Yii::$app->language);
     }
     return $options;
 }
开发者ID:arogachev,项目名称:yii2,代码行数:43,代码来源:FileValidator.php

示例12: getAuditValues

 /**
  * @param Model $model
  * @return array
  */
 protected function getAuditValues($model)
 {
     return [[$model->getAttributeLabel('created_at'), date('d.m.Y', $model->created_at)], [$model->getAttributeLabel('updated_at'), date('d.m.Y', $model->updated_at)]];
 }
开发者ID:kunaksergey,项目名称:crmapp,代码行数:8,代码来源:AuditColumn.php

示例13: addError

 /**
  * Adds an error about the specified attribute to the model object.
  * This is a helper method that performs message selection and internationalization.
  * @param \yii\base\Model $model the data model being validated
  * @param string $attribute the attribute being validated
  * @param string $message the error message
  * @param array $params values for the placeholders in the error message
  */
 public function addError($model, $attribute, $message, $params = [])
 {
     $params['attribute'] = $model->getAttributeLabel($attribute);
     if (!isset($params['value'])) {
         $value = $model->{$attribute};
         $params['value'] = is_array($value) ? 'array()' : $value;
     }
     $model->addError($attribute, Yii::$app->getI18n()->format($message, $params, Yii::$app->language));
 }
开发者ID:sadiqhirani,项目名称:yii2,代码行数:17,代码来源:Validator.php

示例14: clientValidateAttribute

 /**
  * Returns the JavaScript needed for performing client-side validation.
  * @param \yii\base\Model $model the data model being validated
  * @param string $attribute the name of the attribute to be validated.
  * @param \yii\web\View $view the view object that is going to be used to render views or view files
  *         containing a model form with this validator applied.
  * @return string the client-side validation script. Null if the validator does not support
  *         client-side validation.
  * @see \yii\widgets\ActiveForm::enableClientValidation
  */
 public function clientValidateAttribute($model, $attribute, $view)
 {
     // get the pattern
     $pattern = $this->elaboratePattern();
     // get the error message
     $message = $this->message ? $this->message : \Yii::t('yii', '{attribute} is invalid.');
     $message = str_replace('{attribute}', $model->getAttributeLabel($attribute), $message);
     $condition = "!value.match({$pattern})";
     return "\nif(" . $condition . ") {\n    messages.push(" . Json::encode($message) . ");\n}\n";
 }
开发者ID:fangface,项目名称:yii2-concord,代码行数:20,代码来源:AlphaValidator.php

示例15: getErrorParams

 /**
  * @param \yii\base\Model $model the model to be validated.
  * @param string $attribute the name of the attribute to be validated.
  */
 private function getErrorParams($model, $attribute)
 {
     return ['attribute' => $model->getAttributeLabel($attribute), 'other_attributes' => implode(', ', array_map(function ($e) use($model) {
         return $model->getAttributeLabel($e);
     }, $this->otherAttributes))];
 }
开发者ID:petrabarus,项目名称:yii2-eithervalidator,代码行数:10,代码来源:EitherValidator.php


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