Welcome Guest, Not a member yet? Register   Sign In
Sub sub-folders not working in controllers
#1

[eluser]Shpigford[/eluser]
I have the following directory structure for a controller:

/application/controllers/admin/site/configuration.php

So logic would tell me I could access this by:
http://example.com/admin/site/configuration/

But when I do that, I get a 404 error.

If I move the configuration.php file up one level to /admin/configuration.php then I can access it fine at /admin/configuration

What am I missing here?
#2

[eluser]Michael Wales[/eluser]
That URL is looking for an Admin controller, the site() method, and passing configuration as the first parameter to that method.

The easiest way to handle sub-foldered controllers is to use Matchbox (search the forums). Personally, I never find the need to abstract Controllers down to subfolders like this - views on the other hand, yes.
#3

[eluser]Shpigford[/eluser]
Quote:That URL is looking for an Admin controller, the site() method, and passing configuration as the first parameter to that method.
But it doesn't do that when I just have one sub-folder. If I do /admin/configuration.php and access it with /admin/configuration, Configuration is the controller it finds. Is CI out of the box just not capable of having multiple levels of sub-folders in controllers?
#4

[eluser]Michael Wales[/eluser]
Quote:Is CI out of the box just not capable of having multiple levels of sub-folders in controllers?
I can't confirm, for sure, without looking through the code - and I am about to head out for work now. But I believe so, yes.

The framework has to eventually give up on automagically trying to determine what you want to do - and I think one level of folders is where that is.

On a side note - why so many folders? Without having knowledge of your application - it seems odd you don't just place this code within an admin controller, with a configuration method.

I'm almost inclined (and don't take this the wrong way, just trying to help out - as I said, no knowledge of your app) to think you are trying to use these sub-subfolders to manipulate what the end URL will be (which isn't the right way to go about things). Routing is what you should be looking for.
#5

[eluser]Shpigford[/eluser]
Quote:On a side note - why so many folders? Without having knowledge of your application - it seems odd you don’t just place this code within an admin controller, with a configuration method.
Totally valid question. Smile It's mainly for organizational purposes...that I'm totally new to CI so maybe I just don't know any better.

So like I've got a /controllers/admin folder for all the controllers pertaining to an administration area of the site then the admin has about 5 major sections. So I could probably shove all the methods in to fewer files but it just bothers me having a file with like 40 methods.

So the idea here is something like this.

The admin area has a "system" area with the functionality to do things like change site settings as well as set things like shipping (it's a shopping cart).

So I might have something like:
/controllers/admin/system/configuration.php
/controllers/admin/system/shipping.php

Then each of those would have index(), add(), edit(), etc etc.

I'm completely open to organizing things differently...but that's just what makes the most sense to me.
#6

[eluser]xwero[/eluser]
I think you are going to far splitting things up.
But first a question : what other areas are there?
#7

[eluser]Shpigford[/eluser]
Quote:I think you are going to far splitting things up.
But first a question : what other areas are there?
That's quite possible.

Major sections:
Admin
Store (products, wishlists, reviews)
Forums
User administration (meaning user-controlled stuff like settings, avatars, etc)
Collections (a Flickr-like area for users)
#8

[eluser]xwero[/eluser]
So you have 2 frontend controllers : store and forums. I guess you are going to integrate the collections in your store?

For the admin you create a directory admin and in there you create the controllers store, forum, users.
In the store controller you create methods to do all the actions for the products.
In the forum controller you create methods to do all the actions for the forum
and the users controller has all the methods for the collections, profiles, wishlists, ...

I think you are not going to end up with too much methods in a controller. The actions adding and deleting can be in one method and you identify the action using the button name.
#9

[eluser]Shpigford[/eluser]
Yes, the collections would integrate with the store.

So you're saying my /controllers would look something like this?

/controllers/admin/store.php
/controllers/admin/forum.php
/controllers/admin/users.php
/controllers/store.php
/controllers/forum.php
#10

[eluser]adamp1[/eluser]
I had this problem not long ago, someone came up with a solution which actually used less code than the current CI method. Post is here




Theme © iAndrew 2016 - Forum software by © MyBB