This article mainly introduces the relevant information of Yii2 rbac permission control operation step tutorial. Friends in need can refer to it. I hope it will be helpful to everyone.
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 from many people, they said that they followed the owner's steps exactly, and they were exactly the same. Why doesn't the menu appear? Why doesn't it appear? Why doesn't it appear? 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 If you don’t know how to operate, you can click on the detailed operation steps of yii2-gii to operate
3. We open the routing page/admin/route/index and the interface shown below will probably 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 and you will jump to The details page of this permission, as shown in the picture below, select the /user/* series and move it to the right
5. We access the role To add a role on the list page/admin/role/index, 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
# means that we assign the "User Management" permission to the role we just created. In the fourth step, we have assigned "User Management" /user/* series of permissions.
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 Now, we can visit /user/index and have a look. If it is normal, it will be fine. If it is not still prompted that there is no permission, then it is probably your fault. Please start over and do it a few more times.
Related recommendations:
#The code automatic loading mechanism in Yii2
yii2.0 case sharing of integrating Alibaba Cloud oss (picture)
Sharing of a simple method to implement reversible encryption in Yii2 framework
The above is the detailed content of Yii2 implements rbac permission control. For more information, please follow other related articles on the PHP Chinese website!

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download
The most popular open source editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use
