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


PHP Model::attributes方法代码示例

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


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

示例1: attributes

 /**
  * Overrides default [[attributes()]] method.
  * Extracts attributes from the validation rules described in [[rules()]] method.
  *
  * @return array
  */
 public function attributes()
 {
     $attributes = \yii\base\Model::attributes();
     foreach (self::rules() as $rule) {
         if (is_string(reset($rule))) {
             continue;
         }
         foreach (reset($rule) as $attribute) {
             if (substr_compare($attribute, '!', 0, 1) === 0) {
                 $attribute = mb_substr($attribute, 1);
             }
             $attributes[$attribute] = $attribute;
         }
     }
     return array_values($attributes);
 }
开发者ID:hiqdev,项目名称:hipanel-core,代码行数:22,代码来源:ModelTrait.php

示例2: getDetailAttributes

 /**
  * Retrieves detail view attributes configuration using the modelClass.
  * @param Model $model
  * @param array $fields
  * @return array detail view attributes
  */
 public function getDetailAttributes($model, $fields)
 {
     if (!$model instanceof ActiveRecord) {
         return $model->attributes();
     }
     /** @var ActiveRecord $model */
     $formats = $model->attributeFormats();
     $keys = self::getModelKeys($model);
     list($behaviorAttributes, $blameableAttributes) = self::getModelBehaviorAttributes($model);
     $attributes = $model->attributes();
     $versionAttribute = $model->optimisticLock();
     $result = [];
     foreach ($fields as $key => $field) {
         if (is_array($field)) {
             $result[$key] = $field;
             continue;
         } elseif (!is_string($field) && is_callable($field)) {
             $result[$key] = call_user_func($field, $model);
             continue;
         }
         if (in_array($field, $attributes)) {
             if (in_array($field, $keys) || in_array($field, $blameableAttributes) || $field === $versionAttribute) {
                 continue;
             }
             $result[$field] = ['attribute' => $field, 'format' => $formats[$field]];
             continue;
         }
         $relation = $model->getRelation($field);
         if (!$relation->multiple) {
             // validate foreign keys only for hasOne relations
             foreach ($relation->link as $left => $right) {
                 if (in_array($left, $blameableAttributes)) {
                     continue;
                 }
             }
         }
         if (!Yii::$app->user->can($relation->modelClass . '.read')) {
             continue;
         }
         $result[$field] = ['attribute' => $field, 'format' => 'crudLink', 'visible' => true, 'label' => $model instanceof ActiveRecord ? $model->getRelationLabel($relation, $field) : null];
     }
     return $result;
 }
开发者ID:netis-pl,项目名称:yii2-crud,代码行数:49,代码来源:ViewAction.php

示例3: prepareCondition

 /**
  * Prepares where condition
  *
  * @param Query $query
  * @param \yii\base\Model $modelForm
  * @return string
  */
 public function prepareCondition(&$query, $modelForm)
 {
     foreach ($modelForm->attributes() as $attribute) {
         if ($attribute === 'table' || is_null($modelForm[$attribute])) {
             continue;
         }
         $filterConfig = Yii::$app->controller->module->filters[$attribute];
         $query->andWhere("{$filterConfig['attribute']} {$filterConfig['criteria']['operator']} :{$attribute}", [$attribute => $modelForm[$attribute]]);
     }
 }
开发者ID:nineinchnick,项目名称:yii2-audit,代码行数:17,代码来源:AuditController.php

示例4: attributes

 public function attributes()
 {
     return ArrayHelper::merge(ActiveRecord::attributes(), Model::attributes());
 }
开发者ID:tsyrya,项目名称:mybriop,代码行数:4,代码来源:KursSearch.php

示例5: mapServiceAttributes

 protected function mapServiceAttributes(BaseClient &$client, Model &$model)
 {
     $clientUserAttributes = $client->getUserAttributes();
     // go through native client attributes
     foreach ($clientUserAttributes as $attribute => $value) {
         if ($model->canSetProperty($attribute) || in_array($attribute, $model->attributes())) {
             $model->{$attribute} = $value;
         }
     }
     // now find mapping for this service
     $map = SocialMappings::mapForSocialService($this->socialServiceId);
     foreach ($map as $modelAttribute => $socialAttribute) {
         $value = [];
         foreach ($socialAttribute as $attribute) {
             $attribute = trim($attribute);
             if (isset($clientUserAttributes[$attribute])) {
                 $attributeValue = trim($clientUserAttributes[$attribute]);
                 if (!empty($attributeValue)) {
                     $value[] = $clientUserAttributes[$attribute];
                 }
             }
         }
         $value = implode(' ', $value);
         if (!empty($value)) {
             $model->{$modelAttribute} = $value;
         }
     }
 }
开发者ID:cheaterBY,项目名称:yii2-users-module,代码行数:28,代码来源:Social.php

示例6: getGridColumns

 /**
  * Retrieves grid columns configuration using the modelClass.
  * @param Model $model
  * @param array $fields
  * @return array grid columns
  */
 public static function getGridColumns($model, $fields)
 {
     if (!$model instanceof ActiveRecord) {
         return $model->attributes();
     }
     /** @var ActiveRecord $model */
     list($behaviorAttributes, $blameableAttributes) = self::getModelBehaviorAttributes($model);
     /** @var LabelsBehavior $labelsBehavior */
     $labelsBehavior = $model->getBehavior('labels');
     $versionAttribute = $model->optimisticLock();
     $formats = $model->attributeFormats();
     $keys = self::getModelKeys($model);
     $columns = [];
     foreach ($fields as $key => $field) {
         // for arrays and callables, don't generate the column, use the one provided
         if (is_array($field)) {
             $columns[$key] = $field;
             continue;
         } elseif (!is_string($field) && is_callable($field)) {
             $columns[$key] = call_user_func($field, $model);
             continue;
         }
         // if the field is from a relation (eg. client.firstname) treat it as an attribute
         $format = isset($formats[$field]) ? $formats[$field] : $model->getAttributeFormat($field);
         if ($format === 'paragraphs') {
             $format = 'shortText';
         }
         if ($format !== null) {
             if (in_array($field, $keys) && ($labelsBehavior === null || !in_array($field, $labelsBehavior->attributes)) || in_array($field, $behaviorAttributes) || $field === $versionAttribute) {
                 continue;
             }
             if (in_array($field, $labelsBehavior->attributes)) {
                 $columns[] = static::getLinkedColumn($model, $field);
                 continue;
             }
             $columns[] = static::getAttributeColumn($model, $field, $format);
             continue;
         }
         $relation = $model->getRelation($field);
         foreach ($relation->link as $left => $right) {
             if (in_array($right, $blameableAttributes)) {
                 continue 2;
             }
         }
         if (!Yii::$app->user->can($relation->modelClass . '.read')) {
             continue;
         }
         $columns[] = static::getRelationColumn($model, $field, $relation);
     }
     return $columns;
 }
开发者ID:netis-pl,项目名称:yii2-crud,代码行数:57,代码来源:Action.php

示例7: getAttributesDetails

 /**
  * Generate list of attributes details object
  */
 protected function getAttributesDetails()
 {
     $attributes = [];
     $group = $this->getGroup();
     $languages = array_keys(Yii::$app->yee->languages);
     $modelAttributes = parent::attributes();
     $multilingualAttributes = $this->isMultilingual() ? $this->getBehavior('multilingualSettings')->attributes : [];
     foreach ($modelAttributes as $attribute) {
         if (in_array($attribute, $multilingualAttributes)) {
             foreach ($languages as $language) {
                 $field = $language == Yii::$app->language ? $attribute : $this->getMultilingualFieldName("{$attribute}_{$language}");
                 $attributes[$field] = new AttributeDetails($field, $group, $attribute, $language);
             }
         } else {
             $attributes[$attribute] = new AttributeDetails($attribute, $group);
         }
     }
     return $attributes;
 }
开发者ID:yeesoft,项目名称:yii2-yee-settings,代码行数:22,代码来源:BaseSettingsModel.php


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