Class mdm\admin\components\AccessControl

Inheritancemdm\admin\components\AccessControl » yii\base\ActionFilter » yii\base\Behavior » yii\base\Object
Available since version1.0

Access Control Filter (ACF) is a simple authorization method that is best used by applications that only need some simple access control.

As its name indicates, ACF is an action filter that can be attached to a controller or a module as a behavior. ACF will check a set of access rules to make sure the current user can access the requested action.

To use AccessControl, declare it in the application config as behavior. For example.

'as access' => [
    'class' => 'mdm\admin\components\AccessControl',
    'allowActions' => ['site/login', 'site/error']
]

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$allowActions array List of action that not need to check access. mdm\admin\components\AccessControl
$except array List of action IDs that this filter should not apply to. yii\base\ActionFilter
$only array List of action IDs that this filter should apply to. yii\base\ActionFilter
$owner yii\base\Component The owner of this behavior yii\base\Behavior
$user yii\web\User User for check access. mdm\admin\components\AccessControl

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Object
__construct() Constructor. yii\base\Object
__get() Returns the value of an object property. yii\base\Object
__isset() Checks if the named property is set (not null). yii\base\Object
__set() Sets value of an object property. yii\base\Object
__unset() Sets an object property to null. yii\base\Object
afterAction() This method is invoked right after an action is executed. yii\base\ActionFilter
afterFilter() yii\base\ActionFilter
attach() Attaches the behavior object to the component. yii\base\ActionFilter
beforeAction() This method is invoked right before an action is to be executed (after all possible filters.) You may override this method to do last-minute preparation for the action. mdm\admin\components\AccessControl
beforeFilter() yii\base\ActionFilter
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Object
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Object
className() Returns the fully qualified name of this class. yii\base\Object
detach() Detaches the behavior object from the component. yii\base\ActionFilter
events() Declares event handlers for the $owner's events. yii\base\Behavior
hasMethod() Returns a value indicating whether a method is defined. yii\base\Object
hasProperty() Returns a value indicating whether a property is defined. yii\base\Object
init() Initializes the object. mdm\admin\components\AccessControl

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
denyAccess() Denies the access of the user. mdm\admin\components\AccessControl
isActive() Returns a value indicating whether the filer is active for the given action. mdm\admin\components\AccessControl

Property Details

$allowActions public property

List of action that not need to check access.

$user public property

User for check access.

Method Details

beforeAction() public method

This method is invoked right before an action is to be executed (after all possible filters.) You may override this method to do last-minute preparation for the action.

boolean beforeAction$action )
$action yii\base\Action

The action to be executed.

return boolean

Whether the action should continue to be executed.

denyAccess() protected method

Denies the access of the user.

The default implementation will redirect the user to the login page if he is a guest; if the user is already logged, a 403 HTTP exception will be thrown.

void denyAccess$user )
$user \mdm\admin\components\yii\web\User

The current user

throws \mdm\admin\components\yii\web\ForbiddenHttpException

if the user is already logged in.

init() public method

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

void init( )
isActive() protected method

Returns a value indicating whether the filer is active for the given action.

boolean isActive$action )
$action yii\base\Action

The action being filtered

return boolean

Whether the filer is active for the given action.