![]() |
F1, F1, F1 please! Routing / remapping - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: F1, F1, F1 please! Routing / remapping (/showthread.php?tid=28817) |
F1, F1, F1 please! Routing / remapping - El Forum - 03-22-2010 [eluser]Cippo[/eluser] Hello everyone, I use CodeIgniter and Doctrine for a custom CMS that I build for my website. Right now, my uri is something like: http://example.com/home/index/1 ( for the homepage ) and http://example.com/home/index/2 ( for about page - ps: there will be several pages for main navigation ). I want to ask you if there is a way to access http://example.com/about instead of example.com/home/index/2. In this moment, I have two tables in my database: content and pages and I set up a relationship between them. Here’s the function for home model: Code: class Home_Model extends Doctrine_Record And my controller: Code: public function index($id) Code: $route[‘about-me’] = “home/index/2”; Code: $route['(:num)'] = 'home/index/$1'; BUT what I want is to replace the id with the 'slug' that I have created in my database Pages table. PS: I've been looking over the forum all day long but couldn't find that something. I've got some headaches so I'm asking for some help. Thanks F1, F1, F1 please! Routing / remapping - El Forum - 03-22-2010 [eluser]danmontgomery[/eluser] You can define a catch-all route: Code: $route['(:any)'] = 'home/index/$1'; Then do some pseudo-routing in the controller method. Code: public function index($slug) { F1, F1, F1 please! Routing / remapping - El Forum - 03-23-2010 [eluser]Cippo[/eluser] Shall I add the $slug to the index method? I don't really get it. I already have the index file in my controller. F1, F1, F1 please! Routing / remapping - El Forum - 03-23-2010 [eluser]danmontgomery[/eluser] Yes... Each segment in the url after the method name is a parameter passed to that method. So, with that route, something like: Quote:http://www.yourdomain.com/find-this-page Would pass the value "find-this-page" to the index function. |