当前位置: 首页>>代码示例>>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;未经允许,请勿转载。