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?
I think it's better to encrypt your id before passing it. And decrypt it when you reach there. There are many ways of generating such random/encrpted ids. For more security you should not give name like 'user', that you did. Try to modify that even. Hope you got the point...:)
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/UsersController
like so:Instead of
www.mydomain.com/user/update/username
I would usewww.mydomain.com/user/<username>/update
and 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.