本文整理汇总了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;
}
}
示例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));
}
示例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;
}
}
}
示例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());
}
示例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;
}
示例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>';
}