V
V
Vladimir Vasiliev2014-08-14 15:08:37
Yii
Vladimir Vasiliev, 2014-08-14 15:08:37

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

2 answer(s)
S
Sergey, 2014-08-14
@bobahvas

'<username:\w+>' => 'profile/view',
'<username:\w+>/profile' => 'profile/profile',
'<username:\w+>/collection' => 'profile/collection',

If you need to check whether there is such a user in the database at the stage of parsing the rules, you can implement your own rule .

A
Alexander David, 2014-08-14
@alexdevid

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',

I'm not really sure if this will work, but I think it should)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question