![]() |
hiding 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: hiding controller from url (/showthread.php?tid=25480) |
hiding controller from url - El Forum - 12-13-2009 [eluser]bhbutter123[/eluser] right now some of my urls look like http://domain.com/page/pagename, is it possible to make it look like http://domain.com/pagename where pagename is still a method in the controller page? Are there any problems or disadvantages implementing this? hiding controller from url - El Forum - 12-13-2009 [eluser]nicholas.byfleet[/eluser] yes, some clever use of .htaccess could achieve this, although I am not the guy to talk to when it comes to htaccess wizardry. sorry i couldn't be of more help. hiding controller from url - El Forum - 12-13-2009 [eluser]jedd[/eluser] [quote author="bhbutter123" date="1260774045"]right now some of my urls look like http://domain.com/page/pagename, is it possible to make it look like http://domain.com/pagename where pagename is still a method in the controller page? Are there any problems or disadvantages implementing this?[/quote] In this instance, Page is the name of your Controller, and pagename is the method in your controller, yes? The answer is - yes, you can do what you are wanting to do here, using routes. (Read about them in the user guide.) The answer to your second question is a bit more complex - the 'qualified' bit attached to the previous 'yes'. It means that you need to correlate your URL's to various controller/method pairings, and that can sometimes make things more complicated than it would be if you just stuck with the controller/method/param1/param2/... style of URL. Perhaps you just need to re-think your controller and method names - if you stick with the controller = entity or noun, and method = activity or verb - you might find that your URL's make more sense. hiding controller from url - El Forum - 12-13-2009 [eluser]bhbutter123[/eluser] so what would you suggest if I have a whole bunch of static pages I need to display and use the same controller for deciding what page to use, I do not want to use a different controller for each page of my site but don't like having extra segments when http://domain.com/pagename would look better. And yes, page is the controller and pagename is the method. hiding controller from url - El Forum - 12-13-2009 [eluser]jedd[/eluser] [quote author="bhbutter123" date="1260774972"] so what would you suggest if I have a whole bunch of static pages I need to display and use the same controller for deciding what page to use, I do not want to use a different controller for each page of my site but don't like having extra segments when http://domain.com/pagename ... [/quote] The handling of static pages comes up quite regularly - do a search on the forum for titles of 'static page' for some more insight. I'd likely have a controller that handles all my static(ish) pages - I'd call it Meta, but that's just me. Other candidates are Static, Sp (static pages), Site, Info ... etc. Controllers do not have to have long names. hiding controller from url - El Forum - 12-13-2009 [eluser]frenzal[/eluser] $route[':any'] = "page"; or $route['(:any)'] = "page/$1"; but you'll need to provide a route for anything else that isn't allowed to be sent to the page controller, anyway routes should be the easiest solution |