PHP Класс yii2tech\admin\behaviors\ContextModelControlBehavior

For example: items per specific category, comments by particular user etc. This controller finds and creates models including possible filtering context.
См. также: ModelControlBehavior
С версии: 1.0
Автор: Paul Klimov ([email protected])
Наследование: extends ModelControlBehavior
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$contexts 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', ] ]

Открытые методы

Метод Описание
findModel ( $id )
getContext ( string | null $name = null ) : array Return context info by given name.
getContextModel ( string | null $name = null ) : yii\db\ActiveRecordInterface | Model Return active context model by given name.
getContextModelUrl ( string | null $name = null ) : array Composes URL, which leads to the context model details page.
getContextModels ( ) : yii\db\ActiveRecordInterface[] | Model[]
getContextQueryParams ( ) : array Returns query params for currently active contexts, like ['groupId' => 12].
getContextUrl ( string | null $name = null ) : array Composes URL, which leads to the context model index page.
isContextActive ( string | null $name = null ) : boolean Checks if named context is active (present in the query params).
newModel ( )
newSearchModel ( )
setContextModels ( yii\db\ActiveRecordInterface[] | Model[] $contextModels )

Защищенные методы

Метод Описание
findContextModel ( array $config, mixed $id ) : yii\db\ActiveRecordInterface | Model Initializes a particular active context.
findContextModels ( ) : yii\db\ActiveRecordInterface[] | Model[] Finds all active context models.

Описание методов

findContextModel() защищенный Метод

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.
Результат yii\db\ActiveRecordInterface | yii\base\Model context model instance.

findContextModels() защищенный Метод

Finds all active context models.
protected findContextModels ( ) : yii\db\ActiveRecordInterface[] | Model[]
Результат yii\db\ActiveRecordInterface[] | yii\base\Model[] active contexts.

findModel() публичный Метод

public findModel ( $id )

getContext() публичный Метод

If 'null' name provided the first declared context will be returned.
public getContext ( string | null $name = null ) : array
$name string | null context name.
Результат array context config.

getContextModel() публичный Метод

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.
Результат yii\db\ActiveRecordInterface | yii\base\Model default active context model.

getContextModelUrl() публичный Метод

Composes URL, which leads to the context model details page.
public getContextModelUrl ( string | null $name = null ) : array
$name string | null context name.
Результат array URL config.

getContextModels() публичный Метод

public getContextModels ( ) : yii\db\ActiveRecordInterface[] | Model[]
Результат yii\db\ActiveRecordInterface[] | yii\base\Model[] active context models

getContextQueryParams() публичный Метод

This method can be used to compose links.
public getContextQueryParams ( ) : array
Результат array query params.

getContextUrl() публичный Метод

Composes URL, which leads to the context model index page.
public getContextUrl ( string | null $name = null ) : array
$name string | null context name.
Результат array URL config.

isContextActive() публичный Метод

If 'null' name provided, checks if at least one context is active.
public isContextActive ( string | null $name = null ) : boolean
$name string | null context name.
Результат boolean whether context is active.

newModel() публичный Метод

public newModel ( )

newSearchModel() публичный Метод

public newSearchModel ( )

setContextModels() публичный Метод

public setContextModels ( yii\db\ActiveRecordInterface[] | Model[] $contextModels )
$contextModels yii\db\ActiveRecordInterface[] | yii\base\Model[] active context models

Описание свойств

$contexts публичное свойство

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', ] ]
public $contexts