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