Welcome Guest, Not a member yet? Register   Sign In
Best Practice For Processing Posted Data To Controllers?
#1

[eluser]Vheissu[/eluser]
Just a quick question I've been meaning to ask for a while. I've noticed that in various applications built using Codeigniter that POST data is either processed in the controller (this includes form validation) and then sent to a model or library function for processing, or processed inside of the model itself.

So is it better to process sent data inside of the controller or inside of a model like some people seem to be doing? I personally process sent form data in my controllers and then send it to the model in my projecsts.

Which is best MVC practice?
#2

[eluser]Vheissu[/eluser]
[quote author="rmartin345" date="1282734322"]Models are not necessarily directly related to controllers and views.The purpose of the controller is to prepare the dataset you need to display,irrespective of what models are used to store that data.MVC proposes three types of objects in an application,the Model,Views and Controllers.These objects are separated by abstract boundaries which makes MVC more of a paradigm rather than an actual pattern since the communication with each other across those boundaries is not further specified.[/quote]

Your answer kind of confused me. I was merely asking if it is better to process POST data inside of your controllers then send it off to your models or access the POST data directly inside of your models instead of in the controller.
#3

[eluser]WanWizard[/eluser]
The answer is: it's up to you.

I personally have the form processing flow, including validation, in my controllers. Data handling (from simply saving to or retrieving from the database to more complicated operations) happens in models.
I prefer perparing data in the controller and passing it to the model, to directly referencing $this->input->post in the model. The model shouldn't care where the data originated from.




Theme © iAndrew 2016 - Forum software by © MyBB