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


PHP Model::getAttributes方法代码示例

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


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

示例1: getAttributes

 /**
  * @param $values
  * @param Model $model
  */
 protected function getAttributes(&$values, Model $model)
 {
     foreach ($model->getAttributes() as $attribute => $value) {
         $className = explode('\\', get_class($model));
         $className = $className[count($className) - 1];
         $values[$this->getKeyFromAttribute($className, $attribute)] = $value;
     }
 }
开发者ID:vitalik74,项目名称:event-app,代码行数:12,代码来源:BaseSender.php

示例2: getIndexGridColumns

 /**
  * Retrieves grid columns configuration using the modelClass.
  * @param Model $model
  * @param array $fields
  * @return array grid columns
  */
 public function getIndexGridColumns($model, $fields)
 {
     $id = Yii::$app->request->getQueryParam('id');
     $relationName = Yii::$app->request->getQueryParam('relation');
     $multiple = Yii::$app->request->getQueryParam('multiple', 'true') === 'true';
     foreach ($fields as $key => $field) {
         if ((is_array($field) || !is_string($field) && is_callable($field)) && $key === $relationName || $field === $relationName) {
             unset($fields[$key]);
         }
     }
     return array_merge([['class' => 'yii\\grid\\CheckboxColumn', 'multiple' => $multiple, 'headerOptions' => ['class' => 'column-serial'], 'checkboxOptions' => function ($model, $key, $index, $column) use($id, $relationName) {
         /** @var \yii\db\ActiveRecord $model */
         $options = ['value' => is_array($key) ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : $key];
         if (empty($relationName) || $model->{$relationName} === null || trim($id) === '') {
             return $options;
         }
         $relation = $model->getRelation($relationName);
         if ($relation->multiple) {
             /** @var \yii\db\ActiveRecord $relationClass */
             $relationClass = $relation->modelClass;
             if (Action::importKey($relationClass::primaryKey(), $id) === $model->getAttributes(array_keys($relation->link))) {
                 $options['checked'] = true;
                 $options['disabled'] = true;
             }
         } elseif (Action::exportKey($relation->one()->getPrimaryKey()) === $id) {
             $options['checked'] = true;
             $options['disabled'] = true;
         }
         return $options;
     }], ['class' => 'yii\\grid\\SerialColumn', 'headerOptions' => ['class' => 'column-serial']]], self::getGridColumns($model, $fields));
 }
开发者ID:netis-pl,项目名称:yii2-crud,代码行数:37,代码来源:RelationAction.php

示例3: getFieldsByAttributes

 /**
  * @param $fields
  * @param $class
  * @param Model $model
  * @return array
  */
 protected function getFieldsByAttributes(&$fields, $class, Model $model)
 {
     $attributes = $model->getAttributes();
     if (!empty($attributes)) {
         foreach (array_keys($attributes) as $attribute) {
             $fields[] = $class . $this->classNameKeySeparator . $attribute;
         }
     }
 }
开发者ID:vitalik74,项目名称:event-app,代码行数:15,代码来源:Event.php

示例4: marshalModel

 /**
  * Marshal a Yii2 model object to a new array that is formatted in
  * the proper parameter structure required by DynamoDB operations.
  *
  * @param \yii\base\Model $item The model to be marshalled.
  * @return mixed
  */
 public static function marshalModel(\yii\base\Model $item)
 {
     return self::marshaler()->marshalItem($item->getAttributes());
 }
开发者ID:setyolegowo,项目名称:yii2-dynamodb,代码行数:11,代码来源:Marshaler.php

示例5: getModelAttributes

 /**
  * @return array
  */
 protected function getModelAttributes()
 {
     if ($this->searchModel === null || $this->modelClass === null) {
         return [];
     }
     $attributes = [];
     $model = new $this->modelClass();
     foreach ($this->searchModel->getAttributes() as $name => $value) {
         if ($value !== null) {
             $attributes[Html::getInputName($model, $name)] = $value;
         }
     }
     return $attributes;
 }
开发者ID:GAMITG,项目名称:yz2-admin,代码行数:17,代码来源:ActionButtons.php

示例6: showErrors

 /**
  * Return errors as bulleted list for model
  *
  * @param Model $model
  *
  * @return string
  */
 public static function showErrors($model)
 {
     $errors = [];
     foreach ($model->getAttributes() as $attribute => $setting) {
         $error = $model->getFirstError($attribute);
         if (trim($error) != null) {
             $errors[] = $error;
         }
     }
     return '<ul><li>' . implode("</li>\n<li>", $errors) . '</li></ul>';
 }
开发者ID:communityii,项目名称:yii2-user,代码行数:18,代码来源:Module.php


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