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


PHP ActiveForm::field方法代码示例

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


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

示例1: renderRawActiveInput

 /**
  * Renders raw active input based on the attribute settings
  *
  * @param \kartik\form\ActiveForm              $form the form instance
  * @param \yii\db\ActiveRecord|\yii\base\Model $model
  * @param string                               $attribute the name of the attribute
  * @param array                                $settings the attribute settings
  *
  * @return \kartik\form\ActiveField
  * @throws \yii\base\InvalidConfigException
  *
  */
 protected static function renderRawActiveInput($form, $model, $attribute, $settings)
 {
     $type = ArrayHelper::getValue($settings, 'type', self::INPUT_TEXT);
     $i = strpos($attribute, ']');
     $attribName = $i > 0 ? substr($attribute, $i + 1) : $attribute;
     if (!in_array($type, static::$_validInputs)) {
         throw new InvalidConfigException("Invalid input type '{$type}' configured for the attribute '{$attribName}'.'");
     }
     $fieldConfig = ArrayHelper::getValue($settings, 'fieldConfig', []);
     $options = ArrayHelper::getValue($settings, 'options', []);
     $label = ArrayHelper::getValue($settings, 'label', null);
     $hint = ArrayHelper::getValue($settings, 'hint', null);
     $field = $form->field($model, $attribute, $fieldConfig);
     if ($type === self::INPUT_TEXT || $type === self::INPUT_PASSWORD || $type === self::INPUT_TEXTAREA || $type === self::INPUT_FILE || $type === self::INPUT_HIDDEN || $type === self::INPUT_STATIC) {
         return static::getInput($field->{$type}($options), $label, $hint);
     }
     if ($type === self::INPUT_DROPDOWN_LIST || $type === self::INPUT_LIST_BOX || $type === self::INPUT_CHECKBOX_LIST || $type === self::INPUT_RADIO_LIST || $type === self::INPUT_MULTISELECT) {
         if (!isset($settings['items'])) {
             throw new InvalidConfigException("You must setup the 'items' array for attribute '{$attribName}' since it is a '{$type}'.");
         }
         return static::getInput($field->{$type}($settings['items'], $options), $label, $hint);
     }
     if ($type === self::INPUT_CHECKBOX || $type === self::INPUT_RADIO) {
         $enclosedByLabel = ArrayHelper::getValue($settings, 'enclosedByLabel', true);
         if ($label !== null) {
             $options['label'] = $label;
         }
         return static::getInput($field->{$type}($options, $enclosedByLabel), null, $hint);
     }
     if ($type === self::INPUT_HTML5) {
         $html5type = ArrayHelper::getValue($settings, 'html5type', 'text');
         return static::getInput($field->{$type}($html5type, $options), $label, $hint);
     }
     if ($type === self::INPUT_WIDGET) {
         $widgetClass = ArrayHelper::getValue($settings, 'widgetClass', []);
         if (empty($widgetClass) && !$widgetClass instanceof yii\widgets\InputWidget) {
             throw new InvalidConfigException("A valid 'widgetClass' for '{$attribute}' must be setup and extend from 'yii\\widgets\\InputWidget'.");
         }
         return static::getInput($field->{$type}($widgetClass, $options), $label, $hint);
     }
     if ($type === self::INPUT_RAW) {
         return ArrayHelper::getValue($settings, 'value', '');
     }
 }
开发者ID:hsleonis,项目名称:basetech,代码行数:56,代码来源:BaseForm.php


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