Giter Club home page Giter Club logo

yii-behavior-sluggable's Introduction

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: github.com/mintao/yii-behavior-sluggable

Imagine a blog table

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

So you'd like a better URL than that?

http://your-blog.org/index.php?r=blog/show&id=1422

What about

http://your-blog.org/security/nasa-server-hacked-by-hacker-kids

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:

cd <YOUR YII-PROJECT>
mkdir -p protected/extensions/behaviors (optional)
git submodule add git://github.com/mintao/yii-behavior-sluggable.git protected/extensions/behaviors/SluggableBehavior

Demo configuration of this behavior for your model

/**
 * Behaviors for this model
 */
public function behaviors(){
  return array(
    'sluggable' => array(
      'class'=>'ext.behaviors.SluggableBehavior.SluggableBehavior',
      'columns' => array('category', 'title', 'author.name'),
      'unique' => true,
      '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

Download this extension (and fork it):

github.com/mintao/yii-behavior-sluggable

Changelog

  • 2011-04-30 Added update functionality
  • 2011-06-23 Added support for dependent models (see demo configuration, author.name)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.