yii2-user route login

After user press login button

i want to check

pseudocode:

if (\Yii::$app->user->can(‘post’)

go to page post

elseif (\Yii::$app->user->can(‘deletepost’)

go to page deletepost

else

go default page

How can i do this?

i use yii2-user and yii2-rbac dektrium extensions

found this solution.

in the SiteController.php




public function actionIndex()

    {

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

            return Yii::$app->runAction('post/index');

        else

            return $this->render('index');

    }



Is the best solution?