[SOLVED] How to make SEF links?


<?php echo CHtml::link(CHtml::encode($data->Title), $data->url); ?>

gets this url : index.php/article/1076/This+is+a+great+Article+Title

How to make it : index.php/article/1076/This-is-a-great-Article-Title ??

  1. And is there any detail guide how to remove the id or controller altogether like :




I read these but still don’t know how.




I have this in my url rules:


Then I have a function in my post controller which loads a model by slug.

In addition, to hide ‘site/index’, I have this rule:


I hope that helps. :)

Hi jac

Thanks for the head start. I never knew what is a slug. But its a start place for me…

Is slug a generic pattern to solve url problem? Is your slug an own custom "slug" method or are you referring to this extension?



I am actually using the slug behavior. :)

But you don’t have to use it.

Yes, it’s a generic method to have SEO friendly urls.

I use it to generate a sensible url from the title of my blog post.


In order to use that with Yii, you need to modify the view action to take a slug parameter.

It comes from WordPress AFAIK, the term.

Does this mean if there are 2 articles of the same name like

Id | Title

1 | About Us

2 | About Us

in the slug field we create

Id | Title | Slug

1 | About Us | Something

2 | About Us | Other_thing

Then in the link we generate the perma link like



Is it done this way???

I am trying out yiibehaviorsluggable and posted some question to the creator. Hopefully I can get some help from here too if any of you are using the same ext :

Question 1

duplicate entry

Hi mintao, thanks for extension

but can you make it detect duplicate slugs?

currently if I create 2 articles with the same title ("Test Slug") it will generate 2 slugs respectively ("test-slug" and "test-slug-1")

when I edit the artice of "test-slug-1" and change it to "test-slug" it will be accepted and thus there will be 2 "test-slug" in the db

I want to make the Slug field editable in case the user wants to customize it.

how is this handled?

Question 2

count number not consistent

and the count suffix added to the slug is not quite consistent

I created a few articles of the same title and edit the slug fields randomly by removing the "-1" or "-2"… and deleting some articles and add again…

the slugs generated sometimes shows duplicate slugs like

1 "test-slugs"

2 "test-slugs"

3 "test-slugs-2"


1 "test-slugs"

2 "test-slugs-2-1"

It doesn’t checks the rows properly or assign the right numbers although it will work well with 1 or or 2 records without much editing…

I am new to slug thing…is this how it is meant to be? or do you have plans to further update this extension?

Considered this solved! I am starting another advance question here

And how i can populate my database with slugs for the already created rows ?

Loop over the records and do whatever the slug behavior is doing?