Best Pratice For Displaying Views Based On Permissions

Hi,

I’m building my first “real” application with Yii and I would like to know what is the best way to handle different views or layouts based on the users permissions?

For example, admin users should see some admin header on every page, and some additional elements on few of the pages, while some other types of users (or roles) shouldn’t see these links.

Just built your layout for all and have conditions in it, like:




if (user has this role) {

   show this content

} elseif (has this other one) {

   show this

}



This will make your life easier while adding new features and permissions for your users, adding an if statement is easier than adding a whole separate view file and manage it.

You should use RBAC to make different view… use this extension yii2_admin :)