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


PHP Html::getAttributeName方法代码示例

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


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

示例1: render

 /**
  * @inheritDoc
  */
 public function render($content = null)
 {
     if ($content === null) {
         if (!isset($this->parts['{beginWrapper'])) {
             $options = $this->wrapperOptions;
             $tag = ArrayHelper::remove($options, 'tag', 'div');
             $this->parts['{beginWrapper}'] = Html::beginTag($tag, $options);
             $this->parts['{endWrapper}'] = Html::endTag($tag);
         }
         if ($this->label === false) {
             $this->parts['{label}'] = '';
             $this->parts['{beginLabel}'] = '';
             $this->parts['{labelTitle}'] = '';
             $this->parts['{endLabel}'] = '';
         } elseif (!isset($this->parts['{beginLabel'])) {
             $this->parts['{beginLabel}'] = Html::beginTag('label', $this->labelOptions);
             $this->parts['{endLabel}'] = Html::endTag('label');
             $attribute = Html::getAttributeName($this->attribute);
             $this->parts['{labelTitle}'] = Html::encode($this->label ? $this->label : $this->model->getAttributeLabel($attribute));
         }
         if ($this->inputTemplate) {
             $input = isset($this->parts['{input}']) ? $this->parts['{input}'] : Html::activeTextInput($this->model, $this->attribute, $this->inputOptions);
             $this->parts['{input}'] = strtr($this->inputTemplate, ['{input}' => $input]);
         }
     }
     return parent::render($content);
 }
开发者ID:codemix,项目名称:yii2-bs3activeform,代码行数:30,代码来源:ActiveField.php

示例2: header

 public function header($title = null, $options = [])
 {
     if ($title === false) {
         // 为false则不显示
         $this->parts['{header}'] = '';
         return $this;
     }
     $options = array_merge($this->headerOptions, $options);
     $attribute = Html::getAttributeName($this->attribute);
     if ($title !== null) {
         $options['title'] = $title;
     }
     $title = isset($options['title']) ? $options['title'] : Html::encode($this->model->getAttributeLabel($attribute));
     if ($this->collapsed == true) {
         $faclass = "fa-plus";
     } else {
         $faclass = "fa-minus";
     }
     $content = '<h3 class="box-title">' . $title . '</h3>
               <div class="box-tools pull-right">
                 <button class="btn btn-box-tool" data-widget="collapse"><i class="fa ' . $faclass . '"></i></button>
               </div>';
     $this->parts['{header}'] = Html::tag("div", $content, $options);
     return $this;
 }
开发者ID:rocketyang,项目名称:hasscms-app,代码行数:25,代码来源:BoxField.php

示例3:

<?php

use yii\helpers\Html;
use kartik\select2\Select2;
\app\widgets\Select3Assets::register($this);
$pureAttribute = Html::getAttributeName($attribute);
$secondPureAttribute = Html::getAttributeName($secondAttribute);
$error = ($model->hasErrors($attribute) or $model->hasErrors($secondAttribute)) ? 'has-error' : '';
echo '<div id="" class="form-group ' . $error . '">';
echo Html::activeLabel($model, $attribute);
// if ($model->$pureAttribute)
//     echo $this->registerJs('
//     $(function(){
//         var select2Inputid = "'.Html::getInputId($model,$attribute).'";
//         var is_create = false;
//         while(!is_create){
//             if ($("#"+select2Inputid) != undefined){
//                 is_create = true;
//                 $("#"+select2Inputid).select2("val","'.$model->$pureAttribute.'");
//             }
//         }
//     });
//     ');
echo Select2::widget(['model' => $model, 'attribute' => $attribute, 'data' => $data, 'value' => $model->{$pureAttribute}, 'options' => ['placeholder' => $placeholder], 'pluginEvents' => ['change' => 'function (){
                var IdInput = \'' . Html::getInputId($model, $attribute) . '\';
                var NazvanieInput = \'' . Html::getInputId($model, $secondAttribute) . '\';
                if ($(\'#\'+IdInput).val()){
                    $(\'#\'+NazvanieInput).val("");
                }
            }']]);
if (isset($model->{$secondAttribute})) {
开发者ID:tsyrya,项目名称:mybriop,代码行数:31,代码来源:select3.php

示例4: staticInput

 /**
  * Renders a static input (display only).
  *
  * @param array $options the tag options in terms of name-value pairs.
  * @return ActiveField object
  */
 public function staticInput($options = [])
 {
     Html::addCssClass($options, 'form-control-static');
     $content = isset($this->model[Html::getAttributeName($this->attribute)]) ? $this->model[Html::getAttributeName($this->attribute)] : '-';
     $this->parts['{input}'] = Html::tag('p', $content, $options);
     return $this;
 }
开发者ID:CBETOBuT,项目名称:yii2-widgets,代码行数:13,代码来源:ActiveField.php

示例5: renderInput

 /**
  * Renders the special HTML5 input
  * Mainly useful for the color and range inputs
  */
 protected function renderInput()
 {
     Html::addCssClass($this->options, 'form-control');
     $size = isset($this->size) ? ' input-group-' . $this->size : '';
     Html::addCssClass($this->containerOptions, 'input-group input-group-html5' . $size);
     $style = empty($this->html5Container['style']) ? '' : $this->html5Container['style'] . ';';
     if (isset($this->width) && $this->width > 0) {
         $this->html5Container['style'] = $style . 'width:' . $this->width . ';';
     }
     Html::addCssClass($this->html5Container, 'input-group-addon addon-' . $this->type);
     $caption = $this->getInput('textInput');
     $value = $this->hasModel() ? $this->model[Html::getAttributeName($this->attribute)] : $this->value;
     $input = Html::input($this->type, $this->html5Options['id'], $value, $this->html5Options);
     $prepend = static::getAddonContent(ArrayHelper::getValue($this->addon, 'prepend', ''));
     $append = static::getAddonContent(ArrayHelper::getValue($this->addon, 'append', ''));
     $preCaption = static::getAddonContent(ArrayHelper::getValue($this->addon, 'preCaption', ''));
     $prepend .= Html::tag('span', $input, $this->html5Container);
     $content = Html::tag('div', $prepend . $preCaption . $caption . $append, $this->containerOptions);
     Html::addCssClass($this->noSupportOptions, 'alert alert-warning');
     if ($this->noSupport == false) {
         $message = '';
     } else {
         $message = "\n<br>" . Html::tag('div', Yii::t('app', $this->noSupport, ['type' => $this->type]), $this->noSupportOptions);
     }
     return "<!--[if lt IE 10]>\n{$caption}{$message}\n<![endif]--><![if gt IE 9]>\n{$content}\n<![endif]>";
 }
开发者ID:CBETOBuT,项目名称:yii2-widgets,代码行数:30,代码来源:Html5Input.php

示例6: run

 /**
  *
  */
 public function run()
 {
     $view = $this->getView();
     $this->registerScript($view);
     if ($this->hasModel()) {
         if ($this->label) {
             $label = $this->label;
         } else {
             $label = Html::encode($this->model->getAttributeLabel(Html::getAttributeName($this->attribute)));
         }
         $tag = ArrayHelper::remove($this->textOptions, 'tag', 'span');
         $text = Html::tag($tag, $label, $this->textOptions);
         $this->options['label'] = $text;
         $checkbox = Html::activeCheckbox($this->model, $this->attribute, $this->options);
     } else {
         $checkbox = Html::checkbox($this->name, $this->value, $this->options);
         if ($this->label) {
             $tag = ArrayHelper::remove($this->textOptions, 'tag', 'span');
             $text = Html::tag($tag, $this->label, $this->textOptions);
             $checkbox = Html::tag('label', $checkbox . ' ' . $text, $this->labelOptions);
         }
     }
     $input = Html::tag('div', $checkbox, $this->containerOptions);
     echo strtr($this->template, ['{input}' => $input]);
 }
开发者ID:pavlinter,项目名称:yii2-adm-app,代码行数:28,代码来源:Checkbox.php

示例7: begin

 public function begin()
 {
     $attribute = Html::getAttributeName($this->attribute);
     if ($this->model->hasErrors($attribute)) {
         $this->inputOptions['class'] .= ' uk-form-danger';
     }
     return parent::begin();
 }
开发者ID:worstinme,项目名称:yii2-uikit,代码行数:8,代码来源:ActiveField.php

示例8: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->pluginLoading) {
         $this->_loadIndicator = self::LOAD_PROGRESS;
     }
     if ($this->hasModel()) {
         $this->name = ArrayHelper::remove($this->options, 'name', Html::getInputName($this->model, $this->attribute));
         $this->value = $this->model[Html::getAttributeName($this->attribute)];
     }
     $view = $this->getView();
     if (!isset($this->language)) {
         $this->language = Yii::$app->language;
     }
     WidgetAsset::register($view);
 }
开发者ID:CBETOBuT,项目名称:yii2-widgets,代码行数:19,代码来源:InputWidget.php

示例9: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!isset($this->language)) {
         $this->language = Yii::$app->language;
     }
     $this->_lang = $this->getLang($this->language);
     if ($this->pluginLoading) {
         $this->_loadIndicator = self::LOAD_PROGRESS;
     }
     if ($this->hasModel()) {
         $this->name = empty($this->options['name']) ? Html::getInputName($this->model, $this->attribute) : $this->options['name'];
         $this->value = $this->model[Html::getAttributeName($this->attribute)];
     }
     $view = $this->getView();
     AssetBundle::register($view);
 }
开发者ID:komsin,项目名称:yiiexpert1,代码行数:20,代码来源:InputWidget.php

示例10: _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 \yii\base\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 value won't be encoded.
  *
  * See [[renderTagAttributes()]] for details on how attributes are being rendered.
  *
  * @return string the generated label tag
  */
 private function _error($model, $attribute, $options)
 {
     $attribute = Html::getAttributeName($attribute);
     $tag = isset($options['tag']) ? $options['tag'] : 'div';
     unset($options['tag']);
     $options['ng-show'] = 'error.' . $attribute;
     return Html::tag($tag, Html::tag('div', '{{ error.' . $attribute . ' }}'), $options);
 }
开发者ID:rmrevin,项目名称:yii2-application,代码行数:26,代码来源:ActiveField.php

示例11: getClientOptions

 /**
  * Returns the JS options for the field.
  * @return array the JS options
  */
 protected function getClientOptions()
 {
     $attribute = Html::getAttributeName($this->attribute);
     if (!in_array($attribute, $this->model->activeAttributes(), true)) {
         return [];
     }
     $options = [];
     $enableClientValidation = $this->enableClientValidation || $this->enableClientValidation === null && $this->form->enableClientValidation;
     if ($enableClientValidation) {
         $validators = [];
         foreach ($this->model->getActiveValidators($attribute) as $validator) {
             /* @var $validator \yii\validators\Validator */
             $js = $validator->clientValidateAttribute($this->model, $attribute, $this->form->getView());
             if ($validator->enableClientValidation && $js != '') {
                 if ($validator->whenClient !== null) {
                     $js = "if ({$validator->whenClient}(attribute, value)) { {$js} }";
                 }
                 $validators[] = $js;
             }
         }
         if (!empty($validators)) {
             $options['validate'] = new JsExpression("function (attribute, value, messages, deferred) {" . implode('', $validators) . '}');
         }
     }
     $enableAjaxValidation = $this->enableAjaxValidation || $this->enableAjaxValidation === null && $this->form->enableAjaxValidation;
     if ($enableAjaxValidation) {
         $options['enableAjaxValidation'] = 1;
     }
     if ($enableClientValidation && !empty($options['validate']) || $enableAjaxValidation) {
         $inputID = Html::getInputId($this->model, $this->attribute);
         $options['id'] = $inputID;
         $options['name'] = $this->attribute;
         foreach (['validateOnChange', 'validateOnType', 'validationDelay'] as $name) {
             $options[$name] = $this->{$name} === null ? $this->form->{$name} : $this->{$name};
         }
         $options['container'] = isset($this->selectors['container']) ? $this->selectors['container'] : ".field-{$inputID}";
         $options['input'] = isset($this->selectors['input']) ? $this->selectors['input'] : "#{$inputID}";
         if (isset($this->errorOptions['class'])) {
             $options['error'] = '.' . implode('.', preg_split('/\\s+/', $this->errorOptions['class'], -1, PREG_SPLIT_NO_EMPTY));
         } else {
             $options['error'] = isset($this->errorOptions['tag']) ? $this->errorOptions['tag'] : 'span';
         }
         $options['encodeError'] = !isset($this->errorOptions['encode']) || $this->errorOptions['encode'] !== false;
         return $options;
     } else {
         return [];
     }
 }
开发者ID:bmsrox,项目名称:yiicomm,代码行数:52,代码来源:ActiveField.php

示例12: getClientOptions

 /**
  * Returns the JS options for the field.
  * @return array the JS options.
  */
 protected function getClientOptions()
 {
     $attribute = Html::getAttributeName($this->attribute);
     if (!in_array($attribute, $this->model->activeAttributes(), true)) {
         return [];
     }
     $enableClientValidation = $this->enableClientValidation || $this->enableClientValidation === null && $this->form->enableClientValidation;
     $enableAjaxValidation = $this->enableAjaxValidation || $this->enableAjaxValidation === null && $this->form->enableAjaxValidation;
     if ($enableClientValidation) {
         $validators = [];
         foreach ($this->model->getActiveValidators($attribute) as $validator) {
             /* @var $validator \yii\validators\Validator */
             $js = $validator->clientValidateAttribute($this->model, $attribute, $this->form->getView());
             if ($validator->enableClientValidation && $js != '') {
                 if ($validator->whenClient !== null) {
                     $js = "if (({$validator->whenClient})(attribute, value)) { {$js} }";
                 }
                 $validators[] = $js;
             }
         }
     }
     if (!$enableAjaxValidation && (!$enableClientValidation || empty($validators))) {
         return [];
     }
     $options = [];
     $inputID = $this->getInputId();
     $options['id'] = Html::getInputId($this->model, $this->attribute);
     $options['name'] = $this->attribute;
     $options['container'] = isset($this->selectors['container']) ? $this->selectors['container'] : ".field-{$inputID}";
     $options['input'] = isset($this->selectors['input']) ? $this->selectors['input'] : "#{$inputID}";
     if (isset($this->selectors['error'])) {
         $options['error'] = $this->selectors['error'];
     } elseif (isset($this->errorOptions['class'])) {
         $options['error'] = '.' . implode('.', preg_split('/\\s+/', $this->errorOptions['class'], -1, PREG_SPLIT_NO_EMPTY));
     } else {
         $options['error'] = isset($this->errorOptions['tag']) ? $this->errorOptions['tag'] : 'span';
     }
     $options['encodeError'] = !isset($this->errorOptions['encode']) || $this->errorOptions['encode'];
     if ($enableAjaxValidation) {
         $options['enableAjaxValidation'] = true;
     }
     foreach (['validateOnChange', 'validateOnBlur', 'validateOnType', 'validationDelay'] as $name) {
         $options[$name] = $this->{$name} === null ? $this->form->{$name} : $this->{$name};
     }
     if (!empty($validators)) {
         $options['validate'] = new JsExpression("function (attribute, value, messages, deferred, \$form) {" . implode('', $validators) . '}');
     }
     // only get the options that are different from the default ones (set in yii.activeForm.js)
     return array_diff_assoc($options, ['validateOnChange' => true, 'validateOnBlur' => true, 'validateOnType' => false, 'validationDelay' => 500, 'encodeError' => true, 'error' => '.help-block']);
 }
开发者ID:yiisoft,项目名称:yii2,代码行数:54,代码来源:ActiveField.php

示例13:

					<div class="form-group ">
						<div class="controls pemember-password-wrap">
							<?php 
echo Html::submitButton(Yii::t('user', 'Sign in'), ['class' => 'btn btn-primary']);
?>

							<span class="pemember-password text-muted">
								<?php 
echo Html::checkbox(Html::getInputName($model, 'rememberMe'), Html::getAttributeValue($model, "rememberMe"), ["id" => Html::getInputId($model, "rememberMe")]);
?>
								<label for="<?php 
echo Html::getInputId($model, "rememberMe");
?>
"><?php 
echo Html::getAttributeName("rememberMe");
?>
</label>
							</span>
						</div>
					</div>

					<?php 
ActiveForm::end();
?>

					<div class="ptl mb40">
						<?php 
if ($module->enableConfirmation) {
    ?>
						<?php 
开发者ID:rocketyang,项目名称:hasscms-app,代码行数:30,代码来源:login.php

示例14: getFormFields

 /**
  * Retrieves form fields configuration. Fields can be config arrays, ActiveField objects or closures.
  *
  * @param \yii\base\Model|\netis\crud\db\ActiveRecord $model
  * @param array           $fields
  * @param bool            $multiple         true for multiple values inputs, usually used for search forms
  * @param array           $hiddenAttributes list of attribute names to render as hidden fields
  *
  * @return array form fields
  * @throws InvalidConfigException
  */
 public static function getFormFields($model, $fields, $multiple = false, $hiddenAttributes = [])
 {
     if (!$model instanceof \yii\db\ActiveRecord) {
         return $model->safeAttributes();
     }
     $keys = Action::getModelKeys($model);
     $hiddenAttributes = array_flip($hiddenAttributes);
     list($behaviorAttributes, $blameableAttributes) = Action::getModelBehaviorAttributes($model);
     $attributes = $model->safeAttributes();
     $relations = $model->relations();
     if (($versionAttribute = $model->optimisticLock()) !== null) {
         $hiddenAttributes[$versionAttribute] = true;
     }
     $formFields = [];
     foreach ($fields as $key => $field) {
         if ($field instanceof ActiveField) {
             $formFields[$key] = $field;
             continue;
         } elseif (!is_string($field) && is_callable($field)) {
             $formFields[$key] = call_user_func($field, $model);
             if (!is_string($formFields[$key])) {
                 throw new InvalidConfigException('Field definition must be either an ActiveField or a callable.');
             }
             continue;
         } elseif (!is_string($field)) {
             throw new InvalidConfigException('Field definition must be either an ActiveField or a callable.');
         }
         $attributeName = Html::getAttributeName($field);
         if (in_array($attributeName, $relations)) {
             $formFields = static::addRelationField($formFields, $model, $field, $hiddenAttributes, $attributes, $multiple);
         } elseif (in_array($attributeName, $attributes)) {
             if (in_array($attributeName, $keys) || in_array($attributeName, $behaviorAttributes)) {
                 continue;
             }
             $formFields = static::addFormField($formFields, $model, $field, $hiddenAttributes, $multiple);
         }
     }
     return $formFields;
 }
开发者ID:netis-pl,项目名称:yii2-crud,代码行数:50,代码来源:FormBuilder.php

示例15: renderLabelParts

 /**
  * @param string|null $label the label or null to use model label
  * @param array $options the tag options
  */
 protected function renderLabelParts($label = null, $options = [])
 {
     $options = array_merge($this->labelOptions, $options);
     if ($label === null) {
         if (isset($options['label'])) {
             $label = $options['label'];
             unset($options['label']);
         } else {
             $attribute = Html::getAttributeName($this->attribute);
             $label = Html::encode($this->model->getAttributeLabel($attribute));
         }
     }
     $this->parts['{beginLabel}'] = Html::beginTag('label', $options);
     $this->parts['{endLabel}'] = Html::endTag('label');
     $this->parts['{labelTitle}'] = $label;
 }
开发者ID:foundationize,项目名称:yii2-foundation,代码行数:20,代码来源:FnActiveField.php


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