slug-behavior SlugBehavior

  1. Documentation
  2. Change Log

*This extension is now updated to work with non latin characters and and works with 1.2

This extension is to save pretty url's from titles to be used as unique identifier's

Note it overwrite's beforeSave... use:

return parent::beforeSave();

In your model if it contains beforeSave method..

http://www.yiiframework.com/forum/index.php?/topic/4485-slug-behavior/

Discussion

http://www.yiiframework.com/forum/index.php?/topic/4485-slug-behavior/

Documentation

Requirements

one primary key like id, use utf8 strings

Installation
  • Extract the release file under models/behaviors
Usage

Add in model..

public function behaviors(){
    return array(
        'SlugBehavior' => array(
            'class' => 'application.models.behaviors.SlugBehavior',
            'slug_col' => 'slug',
            'title_col' => 'title',
            'max_slug_chars' => 125,
            'overwrite' => false
        )
    );
}

Table example:

CREATE TABLE IF NOT EXISTS `pages` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `title` varchar(125) NOT NULL,
    `slug` varchar(125) NOT NULL,
    `body` text,
    PRIMARY KEY (`id`),
    UNIQUE KEY `slug` (`slug`),
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;

*Aditional notes becarefull of non latin languages they need to be displayed normally with urldecode(); and take up alot of database characters as they are long like %23# etc :P

Change Log

June 3, 2010

Generate slug only if it needs to be saved.. don't clean non latin characters..

September 22, 2009
  • Update uses primary key to see if the slug has changed so it not keeps changing the slug
September 20, 2009
  • Initial release.
11 0
9 followers
1 871 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Others
Tags:
Developed by: mech7
Created on: Sep 20, 2009
Last updated: 13 years ago

Downloads

show all