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


PHP Model::getActiveFieldSettings方法代碼示例

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


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

示例1: renderActiveInput

 /**
  * Render ActiveField input based on provided settings
  *
  * @param ActiveForm $form
  * @param Model|ActiveRecord $model
  * @param string $attribute
  * @param array $settings
  * @return ActiveField|NULL|string
  */
 private function renderActiveInput($form, $model, $attribute, $settings)
 {
     if (is_string($settings) && $settings) {
         // no settings have been provided for the attribute so $settings will be the attribute name
         $attribute = $settings;
         $settings = [];
     }
     $settingsIn = $settings;
     if ($model instanceof AttributeSupportInterface) {
         //$activeConfig = $model->getAttributeConfig($attribute, 'active');
         $activeConfig = $model->getActiveFieldSettings($attribute);
         if ($activeConfig) {
             $settings = array_merge($activeConfig, $settings);
         }
     }
     $spec = false;
     if ($model instanceof YiiActiveRecord) {
         if ($this->spec === null) {
             $this->spec = $this->model->getTableSchema()->columns;
         }
         if ($this->spec && isset($this->spec[$attribute])) {
             $spec = isset($this->spec[$attribute]) ? $this->spec[$attribute] : false;
         }
     }
     $type = ArrayHelper::getValue($settings, 'type', null);
     $typeAutomatic = false;
     $label = null;
     $items = ArrayHelper::getValue($settings, 'items', []);
     if ($items instanceof \Closure) {
         $items = $items($model, $attribute);
     }
     if (!$items) {
         if (is_array($spec->enumValues) && $spec->enumValues) {
             foreach ($spec->enumValues as $k => $v) {
                 if (is_string($v) && $v == '') {
                 } else {
                     $items[$v] = $v;
                 }
             }
         }
     }
     $allowClear = false;
     if ($type === null && $items) {
         // we have been given items so assume a drop down list
         $type = InputField::INPUT_DROPDOWN_LIST;
     }
     if ($type === null) {
         // try to guess the appropriate type
         switch ($attribute) {
             case 'created_at':
             case 'createdAt':
                 $type = InputField::INPUT_STATIC;
                 $label = $model->getAttributeConfig($attribute, 'label');
                 $label = !$label ? ArrayHelper::getValue($settings, 'label', false) : $label;
                 $label = !$label ? 'Created' : $label;
                 $createAttribute = $attribute == 'created_at' ? 'created_by' : 'createdBy';
                 if ($model->hasAttribute($createAttribute)) {
                     if ($model->{$createAttribute} == Yii::$app->user->identity->id) {
                         $settings['options']['value'] = $model->{$attribute} . ' by ' . Yii::$app->user->identity->display_name;
                     } else {
                         $createData = AdminUser::find()->select('display_name')->where(['id' => $model->{$createAttribute}])->limit(1)->asArray()->column();
                         $settings['options']['value'] = $model->{$attribute} . ' by ' . $createData[0];
                     }
                 }
                 break;
             case 'modified_at':
             case 'modifiedAt':
                 $type = InputField::INPUT_STATIC;
                 $label = $model->getAttributeConfig($attribute, 'label');
                 $label = !$label ? ArrayHelper::getValue($settings, 'label', false) : $label;
                 $label = !$label ? 'Last Modified' : $label;
                 $modifiedAttribute = $attribute == 'modified_at' ? 'modified_by' : 'modifiedBy';
                 if ($model->hasAttribute($modifiedAttribute)) {
                     if ($model->{$modifiedAttribute} == Yii::$app->user->identity->id) {
                         $settings['options']['value'] = $model->{$attribute} . ' by ' . Yii::$app->user->identity->display_name;
                     } else {
                         $modifiedData = AdminUser::find()->select('display_name')->where(['id' => $model->{$modifiedAttribute}])->limit(1)->asArray()->column();
                         $settings['options']['value'] = $model->{$attribute} . ' by ' . $modifiedData[0];
                     }
                 }
                 break;
             case 'created_by':
             case 'createdBy':
             case 'modified_by':
             case 'modifiedBy':
             case 'id':
                 $type = InputField::INPUT_STATIC;
                 break;
             default:
                 $type = InputField::getDefaultInputFieldType($attribute, $spec, $settings);
                 if ($type) {
//.........這裏部分代碼省略.........
開發者ID:fangface,項目名稱:yii2-concord,代碼行數:101,代碼來源:FormBuilder.php


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