![]() |
URI Routing Like Wordpress Pages and Posts - 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: URI Routing Like Wordpress Pages and Posts (/showthread.php?tid=37810) |
URI Routing Like Wordpress Pages and Posts - El Forum - 01-21-2011 [eluser]cornofstarch[/eluser] Hello, I'm completely confused on how to do this correctly. I would like the routing to work similar to Wordpress routing. For example, if you type in yoursite.com/about, it will go to the about page. But in this case, it would go to my "about" controller. I got as far as this: routes.php Code: $route['^[0-9a-zA-Z][\w-]*[0-9a-zA-Z]$'] = "pages"; pages.php Code: class Pages extends Controller { But now when I want to redirect to my login controller, it breaks because it matches the condition in routes.php. I'm not sure how to proceed... can someone point me in the right direction on how to solve this? URI Routing Like Wordpress Pages and Posts - El Forum - 01-21-2011 [eluser]RedIgniter[/eluser] I am not really sure what your problem is, can you explain further? URI Routing Like Wordpress Pages and Posts - El Forum - 01-21-2011 [eluser]Phil Sturgeon[/eluser] This is a commonly asked question, answered on SO. http://stackoverflow.com/questions/3725050/codeigniter-best-routes-configuration-for-cms/3960354#3960354 URI Routing Like Wordpress Pages and Posts - El Forum - 01-21-2011 [eluser]Killswitch[/eluser] You can put a route above that with controllers you want to preserve. For example: $route['(login|register)'] = "$1"; That will make it so /login and /register go to your login and register controllers. URI Routing Like Wordpress Pages and Posts - El Forum - 01-21-2011 [eluser]cornofstarch[/eluser] Thank you everyone for the replies. I'm going to try out the methods to see which one gives me the greatest ease, control, and flexibility. URI Routing Like Wordpress Pages and Posts - El Forum - 01-22-2011 [eluser]cornofstarch[/eluser] Hi, I'm trying this method but I'm having trouble with the remap... Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); I keep getting "index" for $method and $params[] is always empty. For example, http://localhost/test/wow/again will result in the following output: index empty I'm trying to get the following output: test wow again What am I doing wrong with the remap? URI Routing Like Wordpress Pages and Posts - El Forum - 01-24-2011 [eluser]cornofstarch[/eluser] For more details go here: http://ellislab.com/forums/viewthread/179020/ The CI manual really needs to be clearer on this for inexperienced people like me. -_-; The example is localhost/test/wow/again. In config/routes.php, I routed all 404 errors to pages.php. Using the controller code above, $method would only show "index" because the method "test" doesn't actually exists in my Pages controller. If I were to add a new method... Code: public function test() ... then I would get the following result in my browser: testwow again I hope this helps someone if they're exploring the remap stuff. |