Link structures |
[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?
[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
[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.
[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/
[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
[eluser]Sean Gates[/eluser]
BTW, my method above is fairly crude. There are other things you need to consider when doing things like this.
[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.
[eluser]WebsiteDuck[/eluser]
Sure, check out Organizing Your Controllers into Sub-folders in the Controllers section of the User Guide. |
Welcome Guest, Not a member yet? Register Sign In |