The topic of this article is the detailed operation steps of rbac permission control. Please pay attention to the operation steps. About configuration and rbac setup , our tutorial on building a perfect backend and implementing rbac permission control in yii2 couldn't be more clear.
However, according to the feedback of many people, they said that they followed the steps of the author exactly, and they were not bad at all. Why is the menu not displayed? Why is it not displayed? Why is it 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 it, you can click on the detailed operation steps of yii2-gii to operate
3. When we open the routing page /admin/route/index, the interface below will appear
If the /user/* series of routes in the picture above do not appear on your left menu, please 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 Add Permission button and add a name and description as shown below
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 set the permissions to "User" as shown below. Manage "Just move it over
This 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 Click to add a 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. Next, we can visit /user/index to take a look. If it is normal, it will be fine. If it still prompts that there is no permission, then it is probably your problem. Let’s start over and do it a few more times, Saonian.