Dynamic Urls

Hello all,

I am very new to yii and I am seriously considering using it for an upcoming project as I have heard alot of positive feedback on the framework. However, I am having a problem figuring out how to get dynamic urls to work. I would like it so that say I have a news controller. I would be able to send a url like news/this-is-a-title. However, I do not want to have to define this in the routes in the main config file. I want to be able to handle it in the controller and tell it whether or not that is a valid url. If anyone can tell me if this is even possible and provide me with an example that would be great.

Thanks in advance for the help.

Put this rule in the array of URL rules:


'news/<slug:[a-z0-9-]+>'=>'news/view',

Then you news controller needs to be able to identify/look up/display news items not only based on id, but based on a slug too.

You can use the slug behavior from the extension repository.

It works for me.

Ok well that seems to be the right solution but what about multiple drilldowns. For example:

/news/cars/honda/civic

Would this work for this as well. I would want to be able to send unlimited amounts of them and be able to control whether it throws a 404 or not in my controller.