Stuck in Guide to implement RBAC


im new to yii and programming (oop). Please help me, i stuck on this step

what is this guide want me to do?

If your permissions hierarchy doesn’t change at all and you have a fixed number of users you can create a console command that will initialize authorization data once via APIs offered by authManager:


namespace app\commands;

use Yii;

use yii\console\Controller;

class RbacController extends Controller


    public function actionInit()


        $auth = Yii::$app->authManager;

        // add "createPost" permission

        $createPost = $auth->createPermission('createPost');

        $createPost->description = 'Create a post';


        // add "updatePost" permission

        $updatePost = $auth->createPermission('updatePost');

        $updatePost->description = 'Update post';


        // add "author" role and give this role the "createPost" permission

        $author = $auth->createRole('author');


        $auth->addChild($author, $createPost);

        // add "admin" role and give this role the "updatePost" permission

        // as well as the permissions of the "author" role

        $admin = $auth->createRole('admin');


        $auth->addChild($admin, $updatePost);

        $auth->addChild($admin, $author);

        // Assign roles to users. 1 and 2 are IDs returned by IdentityInterface::getId()

        // usually implemented in your User model.

        $auth->assign($author, 2);

        $auth->assign($admin, 1);



thanks for help.

Exactly what it states. What’s not working?