Create a human readable url for your Yii model records
Switch branches/tags
Nothing to show
Pull request Compare This branch is 6 commits ahead, 5 commits behind mintao:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

What's it all about?

With this behavior, you can generate an URI for a single or combination of columns in your table. Some call it permalink, others call it slug or human readable url.

Check out the latest version at:

Imagine a blog table

| id | category | title                             |
|  1 | security | NASA Server hacked by hacker kids |
| ...

So you'd like a better URL than that?

What about

Google will love you ;)

How to get it done

  • Add another column called "slug" to your table
  • Download this extension and drop it into your protected/extensions folder,
  • Add the behavior to your model (shown below)

If you're using git, I'd recommend:

mkdir -p protected/extensions/behaviors (optional)
git submodule add git:// protected/extensions/behaviors/SluggableBehavior

Demo configuration of this behavior for your model

 * Behaviors for this model
public function behaviors(){
  return array(
    'sluggable' => array(
      'columns' => array('category', 'title', ''),
      'unique' => true,
      'scopeColumn' => 'language_id',
      'update' => true,
  • class Defines the path where to find the SluggableBehavor.php
  • columns Needs to be an array of the fields to use for slug creation
  • unique Set this to true to ensure a unique slug (Numbers will be added to duplicate slugs, if already existing)
  • update Set this to true is every time you change the entry, the slug should be updated too. Set it to false, if the slug should be only created once
  • scopeColumn The scope of the slug uniquness.

Download this extension (and fork it):


  • 2014-03-20 Added scopeColumn functionality
  • 2011-04-30 Added update functionality
  • 2011-06-23 Added support for dependent models (see demo configuration,