Reputation: 111
I have url, localhost/user/about/id/5
, i want it to convert to a like localhost/john.doe/about
, is it possible to do it in Yii?
john.doe
refers to username
about
refers to action
i want to hide controller name, in this case user
Thanks for the help
Upvotes: 0
Views: 238
Reputation: 3242
Yes you'll need to use a custom UrlRule as in the docs here (Using Custom Url Classes). You can then strip apart the URL in your class, try and find a user name, if it doesn't exists simply return false
and let the rest of the URL rules process.
Bear in mind the higher up the order of URL rules you place your custom one, the more often it will be run (as UrlManager will exit on the first matching rule) so it has performance implications if you just put it right at the top.
Bonus
This will also help you in generating URLs as you can just pass a user name as a parameter to a normal URL and have your class do the complicated bit.
Upvotes: 1