For example: items per specific category, comments by particular user etc.
This controller finds and creates models including possible filtering context.
findContextModel()
protected method
Initializes a particular active context.
protected findContextModel ( array $config, mixed $id ) : yii\db\ActiveRecordInterface | Model |
$config |
array |
context configuration. |
$id |
mixed |
context model primary key value. |
return |
yii\db\ActiveRecordInterface | yii\base\Model |
context model instance. |
findContextModels()
protected method
Finds all active context models.
protected findContextModels ( ) : yii\db\ActiveRecordInterface[] | Model[] |
return |
yii\db\ActiveRecordInterface[] | yii\base\Model[] |
active contexts. |
getContext()
public method
If 'null' name provided the first declared context will be returned.
getContextModel()
public method
If 'null' name provided the first active context model will be returned.
public getContextModel ( string | null $name = null ) : yii\db\ActiveRecordInterface | Model |
$name |
string | null |
context name. |
return |
yii\db\ActiveRecordInterface | yii\base\Model |
default active context model. |
getContextModelUrl()
public method
Composes URL, which leads to the context model details page.
getContextModels()
public method
public getContextModels ( ) : yii\db\ActiveRecordInterface[] | Model[] |
return |
yii\db\ActiveRecordInterface[] | yii\base\Model[] |
active context models |
getContextQueryParams()
public method
This method can be used to compose links.
getContextUrl()
public method
Composes URL, which leads to the context model index page.
isContextActive()
public method
If 'null' name provided, checks if at least one context is active.
setContextModels()
public method
public setContextModels ( yii\db\ActiveRecordInterface[] | Model[] $contextModels ) |
$contextModels |
yii\db\ActiveRecordInterface[] | yii\base\Model[] |
active context models |
$contexts public_oe property
specifies possible contexts.
The array key is considered as context name, value - as context config.
Config should contain following keys:
- class: string, class name of context model.
- attribute: string, name of model attribute, which refers to the context model primary key.
- url: array|string, URL config or route to the controller, which manage context models.
- required: boolean, whether this context is mandatory for this controller or optional.
For example:
php
[
'user' => [
'class' => 'User',
'attribute' => 'userId',
'url' => 'user/view',
]
]