0

Could some one possibly clarify this for me. In the MVC paradigm, the idea is to keep the controller as thin as possible, it is also true that the model is the bit that communicates with data sources such as the database, XML-RPC etc and this is where the business logic should go.

Is the POST and GET data a 'data source' and should that kind of data be handled by the model or should it be by the controller.

I would normally call a method in the model and pass it the post data, the data would be quality checked by the controller and the model method would simply do the insertion or whatever. Should it be though that controller just calls the model method if a post has occured and it is responsible for sanity check, data checks etc.

Gordon
  • 312,688
  • 75
  • 539
  • 559
user505988
  • 507
  • 1
  • 10
  • 23
  • 1
    possible duplicate of [Understanding MVC: Whats the concept of "Fat" on models, "Skinny" on controllers?](http://stackoverflow.com/questions/3109715/understanding-mvc-whats-the-concept-of-fat-on-models-skinny-on-controllers) – Gordon Jan 07 '11 at 09:58
  • 1
    The idea is to have reusable models...because after all model is doing the "hard job" of talking to the database.The controller is not meant to be reusable(although sometimes it can be...), it is just a safe way to make your user interface communicate with your model.So writing controllers that are thin and app specific means that you have a more generic logic to your models and you save yourself lots of time in the future. – rabidmachine9 Jan 07 '11 at 15:32

2 Answers2

0

In my approach the controller just makes sure the data sent is using the right method (POST/GET) and complete (via setting defaults or validating forms) before sending them to the model. For testability i highly suggest to feed your model with the $request->getParams(); $request->getPost() and $request->getQuery() wrappers.

As an additional resource on how to design models, controllers and relationship here a link from a long-time ZF contributors blog: The M in MVC; Why Models are Misunderstood and Unappreciated

Samuel Herzog
  • 3,561
  • 1
  • 22
  • 21
0

I believe that working with POST and GET data falls under the responsibilities of the Controller. I see it as the worker who processes incoming data and sends it to libraries or models, gets the response and routes it to other libraries, models, or views.

kevtrout
  • 4,934
  • 6
  • 33
  • 33