Welcome Guest, Not a member yet? Register   Sign In
How use route in Codeigniter
#1

[eluser]memVN[/eluser]
Hi all.
I have a link as http://demo.com/article/12/abc
Now I want to use route to change this link to as like: http://demo.com/bai-viet-12-a-b-c
But I dont know how to code, who can help me? Thank a lot
#2

[eluser]weboap[/eluser]
ok in the 1st link you are looking for the article by id or month or whatever (12), and title (abc) in the databse.
the basic idea is to have another column called for eg: slug in the article table populated at the entry point of the article, that will utilize url_title(); see http://ellislab.com/codeigniter/user-gui...elper.html

like
Code:
$article_title = 'your article title';
$slug = url_title($article_title);
//save this value to the column

then in reading time, you can look up the article by the slug , take the article title list it in an anchor or whatever with the link http://demo.com/your-article-title
...

hope this help.


#3

[eluser]memVN[/eluser]
@weboap: thank you but I mean that link http://demo.com/article/12/abc with "article" is a controller, and now I want to change it to http://demo.com/bai-viet-12-a-b-c, it's mean change controller "article" to "bai-viet"
I was trying use to Regular Expressions ([a-zA-Z0-9_-]+) to do but not successfully
#4

[eluser]weboap[/eluser]
http://ellislab.com/codeigniter/user-gui...uting.html

"Typically there is a one-to-one relationship between a URL string and its corresponding controller class/method. The segments in a URI normally follow this pattern:
example.com/class/function/id/

In some instances, however, you may want to remap this relationship so that a different class/function can be called instead of the one corresponding to the URL."

mean the controller "bai-vet-12-abc" need to exist???!! , you can check " _remap " but i don't think its gonna do it either.
I'm interested too to see if somebody have any idea....




Theme © iAndrew 2016 - Forum software by © MyBB