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