PHP Class 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.
See also: ModelControlBehavior
Since: 1.0
Author: Paul Klimov ([email protected])
Inheritance: extends ModelControlBehavior
Datei anzeigen Open project: yii2tech/admin Class Usage Examples

Public Properties

Property Type Description
$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 Methods

Method Description
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 )

Protected Methods

Method Description
findContextModel ( array $config, mixed $id ) : yii\db\ActiveRecordInterface | Model Initializes a particular active context.
findContextModels ( ) : yii\db\ActiveRecordInterface[] | Model[] Finds all active context models.

Method Details

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.

findModel() public method

public findModel ( $id )

getContext() public method

If 'null' name provided the first declared context will be returned.
public getContext ( string | null $name = null ) : array
$name string | null context name.
return array context config.

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.
public getContextModelUrl ( string | null $name = null ) : array
$name string | null context name.
return array URL config.

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.
public getContextQueryParams ( ) : array
return array query params.

getContextUrl() public method

Composes URL, which leads to the context model index page.
public getContextUrl ( string | null $name = null ) : array
$name string | null context name.
return array URL config.

isContextActive() public method

If 'null' name provided, checks if at least one context is active.
public isContextActive ( string | null $name = null ) : boolean
$name string | null context name.
return boolean whether context is active.

newModel() public method

public newModel ( )

newSearchModel() public method

public newSearchModel ( )

setContextModels() public method

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

Property Details

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