*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/
Copyright © 2009 by Chris de Kok
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of ?????? nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Available Downloads
| File |
Summary |
Uploaded on |
Downloaded |
|
SlugBehavior.zip (3.6 KB)
|
Pretty urls |
August 17, 2010 |
12 |
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
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