本文整理汇总了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);
}
示例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;
}
示例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]]);
}
}
示例4: attributes
public function attributes()
{
return ArrayHelper::merge(ActiveRecord::attributes(), Model::attributes());
}
示例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;
}
}
}
示例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;
}
示例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;
}