Class ekstazi\crud\actions\Action

Inheritanceekstazi\crud\actions\Action » yii\base\Action
Subclassesekstazi\crud\actions\CreateAction, ekstazi\crud\actions\DeleteAction, ekstazi\crud\actions\IndexAction, ekstazi\crud\actions\UpdateAction, ekstazi\crud\actions\ViewAction

Action is the base class for action classes that implement CRUD.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$checkAccess callable A PHP callable that will be called when running an action to determine if the current user has the permission to execute the action. ekstazi\crud\actions\Action
$modelClass string Class name of the model which will be handled by this action. ekstazi\crud\actions\Action

Public Methods

Hide inherited methods

MethodDescriptionDefined By
init() ekstazi\crud\actions\Action

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
ensureAccess() Ensure this action is allowed for current user ekstazi\crud\actions\Action
findModel() Find model by its pk from params otherwise the not found exception will be thrown ekstazi\crud\actions\Action
findModelByPk() Extract pk from params and find model ekstazi\crud\actions\Action
redirect() Redirect to route passed as param ekstazi\crud\actions\Action
saveModel() ekstazi\crud\actions\Action

Property Details

$checkAccess public property

A PHP callable that will be called when running an action to determine if the current user has the permission to execute the action. If not set, the access check will not be performed. The signature of the callable should be as follows,

function ($model null) {
    
// $model is the requested model instance.
    // If null, it means no specific model (e.g. IndexAction)
}

If callable return false then perform standard access control filter behavior (like in \yii\filters\AccessControl).

$modelClass public property

Class name of the model which will be handled by this action. The model class must implement \yii\db\ActiveRecordInterface. This property must be set.

Method Details

ensureAccess() protected method

Ensure this action is allowed for current user

void ensureAccess$params = [] )
$params array

Params to be passed to {$this->checkAccess}

throws \yii\web\ForbiddenHttpException
findModel() protected method

Find model by its pk from params otherwise the not found exception will be thrown

\yii\db\ActiveRecordInterface findModel$findModel$params )
$findModel callable

A PHP callable that will be called to return the model corresponding to the specified primary key value. If not set, findModelByPk() will be used instead. The signature of the callable should be:

function ($params) {
    
// $params is the params from request
}

The callable should return the model found.

$params array

Params for query

return \yii\db\ActiveRecordInterface

Found model

throws \yii\web\BadRequestHttpException

if error on fetching params for pk occured

throws \yii\web\NotFoundHttpException

if model not exists

findModelByPk() protected method

Extract pk from params and find model

\yii\db\BaseActiveRecord findModelByPk$params )
$params
throws \yii\web\BadRequestHttpException
init() public method

void init( )
throws \yii\base\InvalidConfigException
redirect() protected method

Redirect to route passed as param

mixed redirect$route, \yii\db\ActiveRecordInterface $model )
$route mixed

The route to redirect to. It can be one of the followings:

  • A PHP callable. The callable will be executed to get route. The signature of the callable should be:
function ($model){
    
// $model is the model object.
}

The callable should return route/url to redirect to.

  • An array. Treated as route.
  • A string. Treated as url.
$model \yii\db\ActiveRecordInterface
saveModel() protected method

bool|mixed saveModel$saveMethod, \yii\db\ActiveRecordInterface $model )
$saveMethod callable

A PHP callable that will be called to save model. If not set, {{BaseActiveRecord::save}} will be used instead. The signature of the callable should be:

function($model){
    
// $model is the model object to save.
}

The callable should return status of saving operation

$model \yii\db\ActiveRecordInterface