Routing problems |
[eluser]dalebotha[/eluser]
Hi! I'm having problems understanding how routing works. I read the users guide but I haven't been able to apply it to what I'm doing. Help will be appreciated! I've got: - Pages Controller pointed to a pages table in my db. - I'd like each entry in the pages table to look like this in the URL home -> www.eg.com/home about -> www.eg.com/about Here is my index action in Pages Controller: Code: function Pages() I watched Elliot Haughin's screencasts so a lot of this come from him. This is in my httpd.conf: Code: <Directory "/absolute/url/codeignitor/"> Code: <IfModule mod_rewrite.c> Is this enough info to have a clue? It seems there are soo many factors a play here that I really have no clue where it's going wrong and how to debug it! Would anybody be able to help me? Thanks, Dale
[eluser]dalebotha[/eluser]
This is in routes file: Code: $route['default_controller'] = "pages"; These routes could be total garbage as I really am clueless and don't know how to get clued up. ![]()
[eluser]Colin Williams[/eluser]
Well, clearly in your loop, you are routing 'home' to 'home' and 'home/something' to 'home/something'. Quite useless. I think you want to route 'home' to 'pages/index/home' Code: $route['default_controller'] = "pages";
[eluser]roj[/eluser]
I think the first one was right. The setup is reasonable simple: Code: $route['(.*)'] = "pages/index/$1"; By doing this you set up a simple way to create individual pages. The trouble is that say you want to add a news section to the site. In order to do that you probably want to send those requests to it's own controller. ie set up an exception to the above route. The proceeding bit is to handle any exceptions so with the $pages array you add sections that you don't want to send to the pages controller. So the array would read: Code: $pages = array('news'); The foreach loop then takes each item in the array and writes a route sending it where you would normally find it (as Colin pointed out) eg the news controller. Say you also wanted to add an admin section and authors section then you just add admin & author to the $pages array: Code: $pages = array('news','admin','author'); ...and obvious create the corresponding controllers as normal. Hope that adds a little clarity. |
Welcome Guest, Not a member yet? Register Sign In |