Home >Backend Development >PHP Tutorial >Yii2 rbac permission control operation steps example tutorial
The topic of this article is the detailed operation steps of rbac permission control. Please pay attention to the operation steps. Regarding the configuration and establishment of rbac, our tutorial on building a perfect backend and implementing rbac permission control in yii2 cannot be more clear.
However, according to the feedback of many people, they said that they followed the owner's steps exactly, and there was no difference at all. Why is the menu not displayed? Why is it not displayed? It is not displayed? Emma, I finally found the reason when I was helping people debug in the group. It was not easy. The reason is that you have learned how to build but not how to operate. Ah, ah, let’s talk in detail today about how to operate the permission control of rbac! Of course, the premise is that you have successfully built a perfect backend and implemented rbac permission control as we mentioned above.
Take creating the user table and adding permissions to it as an example.
1. Create the user table, and then the creation is completed. It is very simple and we will not go into details.
2. Use gii to generate model+curd. If you don’t know how to operate, you can click on yii2-gii for detailed operations. Follow the steps
3. We open the routing page /admin/route/index and the interface shown below will probably appear
If your left menu does not appear the /user/* series in the picture above route, click the refresh button next to it to refresh.
Now we move the /user/* series selection on the left to the right
4. We open the permission interface /admin/permission/index
Click the New Permission button and add a name and description as shown below. You can
Click Add. After success, you will jump to the details page of the permission. As shown in the picture below, we select the /user/* series and move it to the right
5 . We visit the role list page/admin/role/index to add a role. Just fill in the name and description. After the addition is successful, it will jump to the role details page. Then we only need to move the permission "User Management" as shown below. That’s it
It means that we assign the "User Management" permissions to the role we just created. In the fourth step, we have assigned the /user/* series of permissions to "User Management".
6. We visit the assignment page /admin/assignment/index to assign the role just added to the current user. Note that it is a role, not a permission. Do not add it repeatedly.
7. If we want the newly added operation "User Management" to be displayed on the menu, we also need to open the menu list page
/admin/menu/index and click on the new menu.
Related reading: Yii2 rbac permission control menu menu example tutorial
At this point, we have basically completed the operation of assigning /user permissions to the current user. Now we can visit /user/index to take a look. If it is normal, it will be fine. If it still prompts that you don’t have permission, then it’s probably your problem. Just try it again and do it again, Saonian.
The above introduces the Yii2 rbac permission control operation steps example tutorial, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.