Welcome Guest, Not a member yet? Register   Sign In
Yet another directory structure question
#1

[eluser]CoffeeBeanDesign[/eluser]
I know there are a million threads on directory structure, I've read through some of them but can't work out my own little issue.

I've built a generic mini CMS with CI. I intend to use it across many sites and am working out the best way to structure my folders. My DB has one table called 'content' and each type of content (news, pages whatever) has it's own reference. In the frontend I have a single content model which returns data determined by the section id. Each controller calls the get_content() function and passes the unique section reference.

At first I used HMVC. However, I've essentially only got two modules - backend and frontend content. It seems a bit unnecessary to have modular extensions when I only have two modules. So the next step was to revert to classic CI and simply create a 'backend' sub folder in models, controllers, views.

I'd be fairly happy with this structure so if I can't get what I want I'm not overly fussed but I thought I might be able to achieve something cleaner. For my own clarity and upgradibility I'd like a single folder called backend (could be anywhere, in application perhaps) with three folders - controllers, models, views. So in essence, standard CI with a single extra module. How would I achieve this?? With custom routes perhaps??

The single extra folder name is fixed so I'm guessing I could add something to Router.php. Given that CI looks for the scaffolding trigger and redirects, surely I can add my 'backend' trigger and then redirect to the backend controllers/models/views folders. It might not be worth the hassle....

Many apologies for the epicness of this post, I've read so many threads on directory structure (and other things) which get confused because the original post doesn't clearly describe the situation.

If you can help me out I'd be very happy.
#2

[eluser]jedd[/eluser]
Hi coffeebean .. I'm unsure what the actual, specific problem is that you are attempting to solve here.

The closest I can see from your message is this:
[quote author="coffeebean" date="1249135373"]For my own clarity and upgradibility I'd like a single folder called backend ...[/quote]

But if that's the case, then you're asking the wrong question, because everything under 'application' (default name - can be changed) belongs to you and is shuffled around as a job lot during upgrades.
#3

[eluser]CoffeeBeanDesign[/eluser]
Hi Jedd,

Thanks for your reply. Indeed, the tenor of your response is appropriate to the futility of my question. I accept that this is purely an aesthetic question.

I've currently got something like the following :

- system
- assets
- application
- controllers
- backend ( dir )
- content
- media
- users
- pages
- jobs
- news
- models
- backend ( dir )
- content
- media
- users
- content
- views
- backend ( dir )
- dataset
- forms
- main
- jobs
- news

I know about the 'backend for each controller in the same subfolder system' but my CMS doesn't match that architecture. So all I was thinking was, wouldn't it be nice if I could put the three backend folders in a single subfolder like this :

- application
- backend
- controllers
- models
- views
- helpers
- controllers
- models
- views
- etc.

Since my original post I have (wasted/spent??) all morning looking into it and to achieve exactly what I want I needed to change Router.php, Loader.php and CodeIgniter.php.

This could possibly be the most pointless modification to CI but I went ahead and did it. What else are Saturday mornings for??

I am no CI expert and there may be a gaping hole in my logic but in brief, this is what I have done :

Set a config array called 'subapps'
Changed _validate_request in Router.php to check to see whether $segments[0] is a subapp
Created fetch_subapp() function to return the subapp folder
Changed include request in CodeIgniter.php to include $RTR->fetch_subapp()
Changed Loader.php to look in the subapp folders first for helpers, plugins, views & models
If no file is found in the subapp folders it still looks in the default folders

I guess I could look into amending the Config class to look for a subapp specific config folder... and perhaps subapp specific errors pages...??

I may have broken CI in the process ( all seems to working OK so far ). I would be very grateful if an expert out there would cast their eyes over my changes.
#4

[eluser]jedd[/eluser]
I agree wholeheartedly with quite a few of your points there.

I would suggest that if your goal is to make upgrades and re-deployments easier, then the changes you have made to the system files Router.php , CodeIgniter.php and Loader.php will have gone quite some way to making your life insanely difficult during upgrades or re-deployments.
#5

[eluser]CoffeeBeanDesign[/eluser]
... it gets worse.

I had a play around enabling separate subapp error and config folders changing the way CI loads the files - if a subapp is defined then it first looks in subapp_folder/errors and if no file is found, it looks for the default file. It all works a treat but involves changing too many system files to keep a clear head.

I might reign in my expectations to just enabling controllers, models and views in the subapp folder. I might be able to work though a simpler way so it can be deployed as an extension.

It may come to nothing. I may well be hyper-over-engineering but it has been a worthwhile journey through the bowels of CI. I have a much better understanding of how it all fits together.... and that can't be a bad thing.

If all I achieve is to make life harder then I'll return to the good ol' standard setup.
#6

[eluser]Eric Barnes[/eluser]
Me personally I use
controllers/
controllers/admin/
modules/
views/
views/front/
views/admin/

That way all controllers share the same models and just views and controllers are different.




Theme © iAndrew 2016 - Forum software by © MyBB