MVC Design - How many controllers can/should/must I have in a CodeIgniter MVC web app project?

前端 未结 2 1485
醉话见心
醉话见心 2020-12-31 08:57

I\'m building a relatively simple web application in PHP using the CodeIgniter MVC framework. I\'ve developed PHP applications before but never in a disciplined manner. I\'m

2条回答
  •  执笔经年
    2020-12-31 09:51

    (This is my subjective opinion - it has treated me well)

    Models should be the meat and bone of your entire applications. The models should handle all business logic and database management. Meanwhile, the controllers should be as thin as possible, only really providing an interface between the model and view.

    For instance, in a login screen, the controller should provide the user with the login view. When the user inputs his information, the controller should handle input validation and forward the input to the model, which should respond with "success" or "failure". Consequently the controller should redirect the user to the dashboard, or send him back to the login screen with an error message - respectively.

    To summarize: Models should be fat, controllers should be thin.

提交回复
热议问题