$attributes public property
List of attributes that are allowed to be sorted. Its syntax can be described using the following example:
[ 'age', 'name' => [ 'asc' => ['first_name' => SORT_ASC, 'last_name' => SORT_ASC], 'desc' => ['first_name' => SORT_DESC, 'last_name' => SORT_DESC], 'default' => SORT_DESC, 'label' => 'Name', ], ]
In the above, two attributes are declared: age
and name
. The age
attribute is a simple attribute which is equivalent to the following:
'age' => [ 'asc' => ['age' => SORT_ASC], 'desc' => ['age' => SORT_DESC], 'default' => SORT_ASC, 'label' => Inflector::camel2words('age'), ]
The name
attribute is a composite attribute:
- The
name
key represents the attribute name which will appear in the URLs leading to sort actions. - The
asc
anddesc
elements specify how to sort by the attribute in ascending and descending orders, respectively. Their values represent the actual columns and the directions by which the data should be sorted by. - The
default
element specifies by which direction the attribute should be sorted if it is not currently sorted (the default value is ascending order). - The
label
element specifies what label should be used when calling link() to create a sort link. If not set, yii\helpers\Inflector::camel2words() will be called to get a label. Note that it will not be HTML-encoded.
Note that if the Sort object is already created, you can only use the full format to configure every attribute. Each attribute must include these elements: asc
and desc
.
public array $attributes = []
Please login to continue.