Welcome Guest, Not a member yet? Register   Sign In
Using $_POST at the model
#13

[eluser]bigtony[/eluser]
[quote author="adijux" date="1250119926"]Well, CodeIgniter User Guide suggests taking $_POST in the model (at lest the example suggests that: http://ellislab.com/codeigniter/user-gui....html#what).[/quote]
I think this is more a case of the user guide trying to keep the example as simple as possible, and shouldn't be interpreted as the recommended way.

IMO, you should use the $this->input fields rather than $_POST for the reasons already stated in this thread, but, getting back to the question in the OP, NOT use either directly in the model if you want maximum flexibility (i.e to maintain the principle of 'loose coupling').

To give an example, in one application I have a function in a model that will add details about a building, but in some cases this data comes from a form and in other cases it can be generated programatically. Had I used $this->input or $_POST it would not have been possible to call it with the programmatically generated data without duplicating the function.

It's only a small amount of extra work to pass post data into the model rather than use it directly, but worth it in the long run.


Messages In This Thread
Using $_POST at the model - by El Forum - 08-12-2009, 06:05 AM
Using $_POST at the model - by El Forum - 08-12-2009, 06:14 AM
Using $_POST at the model - by El Forum - 08-12-2009, 11:04 AM
Using $_POST at the model - by El Forum - 08-12-2009, 11:27 AM
Using $_POST at the model - by El Forum - 08-12-2009, 12:32 PM
Using $_POST at the model - by El Forum - 08-12-2009, 01:54 PM
Using $_POST at the model - by El Forum - 08-12-2009, 03:01 PM
Using $_POST at the model - by El Forum - 08-12-2009, 03:38 PM
Using $_POST at the model - by El Forum - 08-13-2009, 06:41 AM
Using $_POST at the model - by El Forum - 08-13-2009, 10:32 AM
Using $_POST at the model - by El Forum - 08-14-2009, 12:47 AM
Using $_POST at the model - by El Forum - 08-14-2009, 01:02 AM
Using $_POST at the model - by El Forum - 08-14-2009, 01:58 AM
Using $_POST at the model - by El Forum - 08-14-2009, 02:17 AM
Using $_POST at the model - by El Forum - 08-14-2009, 02:21 AM
Using $_POST at the model - by El Forum - 08-14-2009, 02:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB