F1, F1, F1 please! Routing / remapping |
[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
[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) {
[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.
[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. |
Welcome Guest, Not a member yet? Register Sign In |