CodeIgniter Forums
MVC paths to folders alternative - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: MVC paths to folders alternative (/showthread.php?tid=67042)



MVC paths to folders alternative - MickDuprez - 01-06-2017

Hi All,

While I'm quite happy with the MVC pattern I'm wondering if it's possible to set up file pathing so that all files related to a 'page' say are in the one folder.
That is, I'd like to place my model, view and controller files in one folder rather than all controllers in the controller folder and so on.

I like this idea as I can easily grab a folder from an existing project and add it to a new one and have it ready with just a few changes to suit that project.

I would still have partial views such as header and footer files in the core part of the app but I'd like to have content in separate directories like so:

application
       |_> login
       |_> products
       |_> blog
               |_ blog_controller.php
               |_ blog_model.php
               |_ blog_view.php
      |_> home

Is this possible in CodeIgniter?

I have toyed with this while building my own frameworks for learning but I'd like to move to CodeIgniter as I like the way it works and this would be the icing on the cake Smile

If you think this is a bad idea I'm genuinely interested in your thoughts on this.

Thanks for your time,
Mick


RE: MVC paths to folders alternative - ivantcholakov - 01-06-2017

(01-06-2017, 04:34 PM)MickDuprez Wrote: Hi All,

While I'm quite happy with the MVC pattern I'm wondering if it's possible to set up file pathing so that all files related to a 'page' say are in the one folder.
That is, I'd like to place my model, view and controller files in one folder rather than all controllers in the controller folder and so on.

I like this idea as I can easily grab a folder from an existing project and add it to a new one and have it ready with just a few changes to suit that project.

I would still have partial views such as header and footer files in the core part of the app but I'd like to have content in separate directories like so:

application
       |_> login
       |_> products
       |_> blog
               |_ blog_controller.php
               |_ blog_model.php
               |_ blog_view.php
      |_> home

Is this possible in CodeIgniter?

I have toyed with this while building my own frameworks for learning but I'd like to move to CodeIgniter as I like the way it works and this would be the icing on the cake Smile

If you think this is a bad idea I'm genuinely interested in your thoughts on this.

Thanks for your time,
Mick

Your structure looks ok. Something similar I use too.

But these days I am experimenting with a different structure. I prefer every controller to serve one HTTP-request only, normal or AJAX. This seems to me more easily maintainable. See the attached image - it is about a CRUD-module within a panel for administration.

I am not suggesting anything, just sharing a thought.


RE: MVC paths to folders alternative - MickDuprez - 01-06-2017

That looks good and pretty much what I was eluding to, thanks.

So how do you configure CI so that it can find the right files with this style of structure?
I'm just starting to dig through the source but I thought I'd ask here for any tips that could save me some time or give me a head start.

Cheers.


RE: MVC paths to folders alternative - ivantcholakov - 01-06-2017

@MickDuprez

Probably I'll finish this work the next week. Make your profile in this forum to accept private messages and I will send you a link to the source when I get ready.


RE: MVC paths to folders alternative - MickDuprez - 01-06-2017

(01-06-2017, 10:17 PM)ivantcholakov Wrote: @MickDuprez

Probably I'll finish this work the next week. Make your profile in this forum to accept private messages and I will send you a link to the source when I get ready.

That would be great ivantcholakov, will enable pm's, just experimenting a bit with paths now and look forward to your work.
cheers.