How to structure controllers in Codeigniter?
I was wandering what is the best way of structuring Codeigniter Controllers.
Let me explain: as far as I know you should have a corresponding Model and Controller for each 'object' you are representing; but there are some people that argue it's better to group actions into website sections.
For exampl开发者_JAVA技巧e:
/ /controllers/user.php /controllers/order.php
As opposed to:
/ /controllers/front.php /controllers/admin.php
If you go with the second structure I thing you'll just end up with long and and messy controllers.
So what the arguments and why is one better than the other ?
May be the best answer is a mixture of both, using modules, HMVC.
Use Modular Extensions for Codeigniter: http://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/overview - it will allow you to break your code into reusable modules. Modules are like applications within your application and can have their own libraries, controllers, models and anything else.
Once you go modular, you'll never go back to sub folders again which get messy when you have a few of them anyway.
Why don't you try using subfolders?
controllers/front/
user.php
order.php
controllers/admin/
//admin controllers
models/front/
user.php
order.php
models/admin/
//admin models
精彩评论