CodeIgniter Forums
remove controller from url? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: remove controller from url? (/showthread.php?tid=20398)



remove controller from url? - El Forum - 07-08-2009

[eluser]thebwit[/eluser]
Ok so I built a massive controller to handle all the requests. It works the way I want it to which is fine. However here's the problem.

Currently urls look like http://mysite.com/page/news/Breaking News or mysite.com/page/interview/Megan Fox

I don't want to display "page" in my urls.

Anyone have an idea how to accomplish this without hacking any core files?


remove controller from url? - El Forum - 07-08-2009

[eluser]Chad Fulton[/eluser]
I think you will want to use the Routing feature. Something like:

Code:
$routes['(:any)'] = 'page/$1';

Although it sounds like you're not interested in a critique of the "one big controller" approach, I do want to mention that it will not be scalable or (probably) maintainable in the long run. You should think about breaking it up, maybe.


remove controller from url? - El Forum - 07-08-2009

[eluser]thebwit[/eluser]
Ahh thanks for that. I knew I had seen something somewhere about this. I do know about the pro's and cons of one big controller and I think that in this implementation it is fine as there is a fixed limit of functions. Thanks again.


remove controller from url? - El Forum - 07-08-2009

[eluser]thebwit[/eluser]
The $1 doesn't work. Is there something I am missing? Keep in mind that of my url: mysite.com/page/news/Breaking

That news is still a function of the page controller.


remove controller from url? - El Forum - 07-08-2009

[eluser]thebwit[/eluser]
Ok after some more messing around and re-reading the routes stuff in the user guide I got it working. Thanks again for pointing me in the right direction.


remove controller from url? - El Forum - 07-08-2009

[eluser]slowgary[/eluser]
Did you put Chad's route into your routes.php file? It looks right to me, based on the routing section of the user guide.


remove controller from url? - El Forum - 07-08-2009

[eluser]thebwit[/eluser]
i had to do something a little more specific. I put:
Code:
$oute['news/(:any)'] = "page/news/$1";
and so on and so forth for each of the functions.

This way also if I split things up to not be a giant controller I just have to change the route and I am good.