Error in Access Control at use function "can"


I am try implementation RBAC, using DbManager.

But when trying to verify access with:

if (\Yii::$app->user->can('createPost')) {

    // create post


Show this error:

Call to a member function checkAccess() on a non-object

How do I find out the cause of the problem?


Could you show us the stack traces?

I’m sorry, but I’m newbie :)

What is "stack trace" and how do I get it?

This is my page error:

 PHP Fatal Error – yii\base\ErrorException

Call to a member function checkAccess() on a non-object

    1. in C:\Wamp\www\basic\vendor\yiisoft\yii2\web\User.php at line 661


         * [[\yii\rbac\ManagerInterface::checkAccess()]] to obtain the up-to-date access result. Note that this

         * caching is effective only within the same request and only works when `$params = []`.

         * @return boolean whether the user can perform the operation as specified by the given permission.


        public function can($permissionName, $params = [], $allowCaching = true)


            if ($allowCaching && empty($params) && isset($this->_access[$permissionName])) {

                return $this->_access[$permissionName];


            $access = $this->getAuthManager()->checkAccess($this->getId(), $permissionName, $params);

            if ($allowCaching && empty($params)) {

                $this->_access[$permissionName] = $access;



            return $access;




         * Returns auth manager associated with the user component.

    2. in C:\Wamp\www\basic\vendor\yiisoft\yii2\base\InlineAction.php at line 55 – app\controllers\PostController::actionCreate()

    3. in C:\Wamp\www\basic\vendor\yiisoft\yii2\base\InlineAction.php at line 55 – call_user_func_array:{C:\Wamp\www\basic\vendor\yiisoft\yii2\base\InlineAction.php:55}()

    4. in C:\Wamp\www\basic\vendor\yiisoft\yii2\base\Controller.php at line 151 – yii\base\InlineAction::runWithParams()

    5. in C:\Wamp\www\basic\vendor\yiisoft\yii2\base\Module.php at line 455 – yii\base\Controller::runAction()

    6. in C:\Wamp\www\basic\vendor\yiisoft\yii2\web\Application.php at line 84 – yii\base\Module::runAction()

    7. in C:\Wamp\www\basic\vendor\yiisoft\yii2\base\Application.php at line 375 – yii\web\Application::handleRequest()

    8. in C:\Wamp\www\basic\web\index.php at line 12 – yii\base\Application::run()



    require(__DIR__ . '/../vendor/autoload.php');

    require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');


    $config = require(__DIR__ . '/../config/web.php');


    (new yii\web\Application($config))->run();

check once main.php file, these lines are available or not.

I am get same error because of this.

return [     

    'components' => [         

        'authManager' => [             

            'class' => 'yii\rbac\DbManager',         




You got it and showed it. :)

It enables you to locate the exact place where the error occurred.

The following are the important lines:

It tells that "$this->getAuthManager()" returned null.

As @ilaiya has suggested, it seems like that you have not configured the auth manager correctly.


'authManager' => [

            'class' => 'yii\rbac\DbManager',


I had put this in "config/console.php" had to be in "config/web.php".