![]() |
Link structures - 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: Link structures (/showthread.php?tid=26199) |
Link structures - El Forum - 01-08-2010 [eluser]Jmz[/eluser] I've been reading up on CI and I think I have the basics, but there's one thing I can't work out about the link structure. Say I'm making a blog where a user has an admin panel and an add page option. My class for the admin panel would look like: Code: Class Admin extends Controller{ If I go to mysite.com/admin it does whatever is in the Index function. If I go to mysite.com/admin/add_page it does whatever is in the Add_page function. Makes sense. What if I want to change the link to mysite.com/admin/pages/add_page so that it's more organised? Can I do this? Link structures - El Forum - 01-08-2010 [eluser]n0xie[/eluser] Might be easier to make a folder in your controllers direcotry named admin, and then add a page controller there with a method 'add': Code: application Link structures - El Forum - 01-08-2010 [eluser]Jmz[/eluser] That works! Thanks. Link structures - El Forum - 01-08-2010 [eluser]Jmz[/eluser] I think I've hit a snag. If I go to mysite.com/admin I want to show an admin home page. I've tried adding an admin.php controller like: Code: application With the index function to show the admin panel home page but then if I go to mysite.com/admin/pages it still shows the admin home rather than the pages home. Link structures - El Forum - 01-08-2010 [eluser]WebsiteDuck[/eluser] You need to get rid of admin.php and create /controllers/admin/home.php (or whatever you have your default_controller set to in /config/routes.php) The default_controller works for any folder in your controllers folder. /controllers/home.php is default for example.com/ /controllers/admin/home.php is default for example.com/admin/ Link structures - El Forum - 01-08-2010 [eluser]Sean Gates[/eluser] If you want you can set routing up from within your controller. Example: Code: Class Admin extends Controller{ Then you can use either: Code: http://somesite.com/admin/pages/add_page or Code: http://somesite.com/admin/add_page Link structures - El Forum - 01-08-2010 [eluser]Sean Gates[/eluser] BTW, my method above is fairly crude. There are other things you need to consider when doing things like this. Link structures - El Forum - 01-09-2010 [eluser]Jmz[/eluser] Thanks for the replies, is there a part of the user guide or some other article I could read that would explain stuff like this? It seems the things I have read don't go into that much detail. Link structures - El Forum - 01-09-2010 [eluser]WebsiteDuck[/eluser] Sure, check out Organizing Your Controllers into Sub-folders in the Controllers section of the User Guide. |