Posts tagged with slug

Yii slug behavior

Make your url's look pretty, for search engine's and human's :) 

Download

How to use

Just extract the file and drop it in your components directory. I always keep my behaviors seperate but this depends on your structure.

You will need to have two fields in your table, one with the title or name and the second one where you store the slug make this a varchar.

Now add the behavior in your model, rename the title and slug column to the fields in your database

 

/**
 * Model behaviors
 * @return array
 */
public function behaviors() {
	return array(
		'SlugBehavior' => array(
			'class' => 'SlugBehavior',
			'slug_col' => 'slug',
			'title_col' => 'title',
			'overwrite' => false,
		),
	);
}

 

Now if you save the model the slug will be saved automatically.

*It should now work with high utf 8 ranges too like asian characters but I haven't tested all of them. Let me know if you find any issues.