Answer the question
In order to leave comments, you need to log in
How to properly organize routing in Yii?
There is a task to arrange routing like:
http : //domain.com/{username}
http : //domain.com/{username}/profile
http : //domain.com/{username}/collection
and so on.
Accordingly, {username} is a variable that contains a valid username. All usernames are stored in the database in the users table.
what is the best way to organize such routing, while maintaining the existing functionality?
Answer the question
In order to leave comments, you need to log in
'<username:\w+>' => 'profile/view',
'<username:\w+>/profile' => 'profile/profile',
'<username:\w+>/collection' => 'profile/collection',
depending on what existing functionality you have,
for example, you have a UserController with methods
- actionDetails($username)
- actionProfile($username)
- actionCollection($username)
then in routes something like this:
'<username:\w+>' => 'user/details',
'<username:\w+>/profile' => 'user/profile',
'<username:\w+>/collection' => 'user/collection',
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question