Yii 1.1: dburlmanager

Dynamic URL rules based on database (provides pretty permalinks or friendly URLs)

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:






  • Yii 1.1.3


  • Extract the extension directory under protected/extensions

Usage by examples

Setting the extension up (on application configuration file):


Setting up a dynamic rule:

    // A dynamic rule.
    // Now additional standard rules.

For further instructions, look at the comment blocks in the beginning of the class file.

Change Log

August 31, 2010

  • Initial release: 1.0.

Total 8 comments

#12363 report it
globaleyeglasses at 2013/03/15 02:05pm
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...

#6333 report it
Chris83 at 2011/12/30 02:38pm
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

#3458 report it
Rodrigo Coelho at 2011/04/14 02:49am
@sebas, @robregonm

@sebas, @robregonm, Any comment? Did the extension work well for you?

#3457 report it
Rodrigo Coelho at 2011/04/14 02:48am

@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.

#3455 report it
Rodrigo Coelho at 2011/04/14 02:45am

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

#2732 report it
Besnik at 2011/02/02 04:12pm
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!

#1955 report it
sebas at 2010/10/19 09:39am
Nice idea!

I like your Idea, I'll try it later...

#129 report it
robregonm at 2010/09/01 01:04pm
Excellent idea.

Very good, I'll give it a try.

Leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: MIT License
  • Developed by: Rodrigo Coelho
  • Category: Others
  • Votes: +9
  • Downloaded: 1,542 times
  • Created on: Aug 31, 2010
  • Last updated: Jun 25, 2011