Provides dynamic database-based URL rules.
Note: As of Yii 1.1.8, this may not be needed anymore. Please refer to custom URL rule classes in the guide.
These dynamic rules are like Wordpress' "pretty permalinks" or "friendly URLs". You do not have to have the controller name (or ID) on the URL: this extension can handle the request URI and route it to the correct controller.
http://mystore.com/blue-coffe-mug
http://myblog.com/my-first-post
protected/extensions'urlManager'=>array( 'class'=>'ext.DbUrlManager.EDbUrlManager', 'urlFormat'=>'path', 'connectionID'=>'db', ... ),
'rules'=>array( // A dynamic rule. '<author:[\w-]+>/<post:[\w-]+>'=>array( 'post/view', 'type'=>'db', 'fields'=>array( 'author'=>array( 'table'=>'tbl_author', 'field'=>'author_name' ), 'post'=>array( 'table'=>'tbl_post', 'field'=>'post_slug' ), ), ), // Now additional standard rules. '<controller:\w+>/<id:\d+>'=>'<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', ),
For further instructions, look at the comment blocks in the beginning of the class file.
Total 8 comments
Undefined index: value protected/extensions/DbUrlManager/EDbUrlManager.php(307) in main.php config:
'<alias:[-.a-z1-9]+>'=>array( 'product/view', 'type'=>'db', 'fields'=>array( '<alias:[-.a-z1-9]+>'=>array( 'table'=>'zp_catalog_product', 'field'=>'url' ), ), ),
public function actionView($alias) { $this->layout='//layouts/column1'; $model=Product::model()->findByAttributes(array('url'=>$alias)); $this->render('view',array( 'model'=>$model, )); }
it works if I use: '<alias:[-.a-z1-9]+>'=>'product/view', but then I have categories too...
You can also achieve this with the means provided my by SEO extension, although the approach is quite different and it doesn't require to query the database.
SEO extension
@sebas, @robregonm, Any comment? Did the extension work well for you?
@besnik, I believe that using just plain SQL is better to avoid the extra load of the Active Record objects, since the checks are really simple.
Dear, I expect to cover at least some of the TODOs soon. The extension will have better performance with the caching implemented. The new features in Yii 1.1.7 will ease a lot this task.
Thank you, Rodrigo Coelho - mentel
It looks very interesting the way you specify routes. I'll give it a try.
A suggestion though: it seems more "the Yii way" to specify a model/attribute instead of a table/field!
I like your Idea, I'll try it later...
Very good, I'll give it a try.
Leave a comment
Please login to leave your comment.