I am using the yii framework and have different user accounts. When I want to have a look at the view page of user 4 I have to enter an url like www.mydomain.com/user/4 for update I have www.mydomain.com/user/update/4.
Is there a way so that I can hide the user id from the url line?
How can I set a route like www.mydomain.com/user/username and www.mydomain.com/user/update/username? Do I have to modify the routes?
What if the username contains an @ symbols?
If each user has a unique username, you can describe a route that doesn’t show their user id by putting this custom routing rule in
config/main:The
\S+should accept “@”. Then pass that username tocontrollers/UsersControllerlike so:Instead of
www.mydomain.com/user/update/usernameI would usewww.mydomain.com/user/<username>/updateand put this in the above urlManager rules array:and this in
UsersController:You can also generate a unique, random number for each user before creation and route based on that number.