Welcome Guest, Not a member yet? Register   Sign In
Which route should I take?
#1

[eluser]TheFuzzy0ne[/eluser]
Hi everyone, and a happy new year to all!


It's stupid question time again. I am trying to design a simple bespoke admin control panel for a client, and I was wondering about how to have the default page for the control panel displayed.

Now, I know that CodeIgniter URLs are structure like so: mydomain.tld/controller/method/... But I'd like to break the control panel up into separate files (one for each admin module (forum, blog, user management etc...). Basically, the URLs will have this kind of structure.

mydomain.tld/admin/
mydomain.tld/admin/forums/
mydomain.tld/admin/blogs/
mydomain.tld/admin/users/

admin is just a directory, not a controller, the controllers are what follow, but I am wondering if there's any method other than using routing that will allow the first URL to produce a page (which will essentially be the index of the control panel. At the moment, mydomain.tld/admin/ just seems to redirect back to the homepage (which I thought was rather odd). Is there something I am missing here, or is routing the only answer?

Is there any reason why CodeIgniter should not look for a controller named "index", if the first parameter is an existing directory, and there is no controller with that name? I'm sure there is a good reason, but I'd be interested to know if I achieve what I want without routing.

Thanks in advance.
#2

[eluser]simshaun[/eluser]
Check config/routes.php
$route['default_controller'] = 'homepage' is what I've got mine setup as.

Controllers directory looks like this:
Code:
/controllers/admin/homepage.php  -> accessed at http://localhost/admin/
/controllers/admin/forums.php    -> accessed at http://localhost/admin/forums/
/controllers/admin/blogs.php     -> accessed at http://localhost/admin/blogs/
/controllers/homepage.php        -> accessed at http://localhost/
/controllers/bla.php             -> accessed at http://localhost/bla/
#3

[eluser]TheFuzzy0ne[/eluser]
Thanks for your reply. I'm not sure if I made myself clear. What happens with your Web site if someone navigates to http://yourdomain.tld/admin/ ? This is what I am curious about. I know I can set up a route that will redirect to a default controller within the admin directory, but I was just wondering if there was another way that didn't involve routing, perhaps some kind of methodology that CodeIgniter uses that I wasn't aware of.
#4

[eluser]simshaun[/eluser]
$route['default_controller'] is a global config key that CodeIgniter uses.
You don't have to actually add it.. it's already there.

Let us say $route['default_controller'] = 'homepage';

When someone navigates to http://yourdomain.tld/admin/,
(This may not be exact, but will give you the idea)

1. CodeIgniter looks for an admin controller in controllers/ but finds none.
2. CodeIgniter looks for an admin directory in controllers/, finds one!
3. No controller specified after /admin/ in the URL, so CI looks for $route['default_controller'] in controllers/admin/ directory.
4. controllers/admin/homepage.php is found. Controller exists so run it.

If in your system directory, controllers/admin/homepage.php didn't exist... I believe CI returns a 404.
#5

[eluser]TheFuzzy0ne[/eluser]
Aaaaah. Please excuse my ignorance. Now it makes sense. The default controller is exactly that, a default controller for all sub-directories, not just for the initial home page. Thanks for clearing that up for me.




Theme © iAndrew 2016 - Forum software by © MyBB