CodeIgniter Forums
How use route in Codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: How use route in Codeigniter (/thread-51653.html)



How use route in Codeigniter - El Forum - 05-11-2012

[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


How use route in Codeigniter - El Forum - 05-11-2012

[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-guide/helpers/url_helper.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.





How use route in Codeigniter - El Forum - 05-12-2012

[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


How use route in Codeigniter - El Forum - 05-12-2012

[eluser]weboap[/eluser]
http://ellislab.com/codeigniter/user-guide/general/routing.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....