DbUrlManager extension. ¶
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.
Examples of clean and friendly URLs made possible by this extension: ¶
http://mystore.com/blue-coffe-mug
http://myblog.com/my-first-post
Resources ¶
Documentation ¶
Requirements ¶
- Yii 1.1.3
Installation ¶
- Extract the extension directory under
protected/extensions
Usage by examples ¶
Setting the extension up (on application configuration file): ¶
'urlManager'=>array(
'class'=>'ext.DbUrlManager.EDbUrlManager',
'urlFormat'=>'path',
'connectionID'=>'db',
...
),
Setting up a dynamic rule: ¶
'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.
Change Log ¶
August 31, 2010 ¶
- Initial release: 1.0.
Excellent idea.
Very good, I'll give it a try.
Nice idea!
I like your Idea, I'll try it later...
Nice work.
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!
Update
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
@besnik
@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.
@sebas, @robregonm
@sebas, @robregonm, Any comment? Did the extension work well for you?
Alternative solution
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
Undefined index: value
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...
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.