CodeIgniter Forums
Using $_POST at the model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Using $_POST at the model (/showthread.php?tid=21519)

Pages: 1 2


Using $_POST at the model - El Forum - 08-12-2009

[eluser]urrus[/eluser]
Hi

I'm just starting using CodeIgnitor, and it's looks like I going to work this system for long time. But there is question:

Why I cannot access tho the $_POST array out of the model?


Using $_POST at the model - El Forum - 08-12-2009

[eluser]urrus[/eluser]
Sorry, I've made a mistake and misprint in my program. Sorry. Everything works.


Using $_POST at the model - El Forum - 08-12-2009

[eluser]renownedmedia[/eluser]
I've got a question... Should $_POST be accessed in the Model or in the Controller? I know it works either way, but which is the correct method? Putting it in the controller and sending a copy to the model would be redundant but would also allow for more code re-use...


Using $_POST at the model - El Forum - 08-12-2009

[eluser]urrus[/eluser]
Yep, put $_POST in controller it more appropriate for MVC. But in this case I some how mix up $_POST with a $_SERVER (it because I catch a could, and really hot now). And I'm crating small sub system that tracked how many time user spend at the current web page, so I need some part of code I could put everywhere.

My algorithm has two main parts, first one is check time when PHP scripts run. Second is to send Ajax request on onClose event.

May be You have advises how to do it best?


Using $_POST at the model - El Forum - 08-12-2009

[eluser]Edmundas Kondrašovas[/eluser]
[quote author="Renowned Media" date="1250114656"]I've got a question... Should $_POST be accessed in the Model or in the Controller? I know it works either way, but which is the correct method? Putting it in the controller and sending a copy to the model would be redundant but would also allow for more code re-use...[/quote]
Well, CodeIgniter User Guide suggests taking $_POST in the model (at lest the example suggests that: http://ellislab.com/codeigniter/user-guide/general/models.html#what). Personally, I don't think you can go too wrong either way. However, I prefer my controllers to be as simple and “skinny“ as possible.


Using $_POST at the model - El Forum - 08-12-2009

[eluser]kirkaracha[/eluser]
The user guide recommends using the Input Class ($this->input->post('title')) instead of using $_POST directly ($_POST['title']).


Using $_POST at the model - El Forum - 08-12-2009

[eluser]Colin Williams[/eluser]
Ideally the controller should handle all input, and having the model accessing $_POST is like having it handle the input in some way. Although, to be honest, the only thing you might lose by going this route is an argument about MVC. I don't know that your application will suffer.


Using $_POST at the model - El Forum - 08-12-2009

[eluser]Edmundas Kondrašovas[/eluser]
[quote author="kirkaracha" date="1250124896"]The user guide recommends using the Input Class ($this->input->post('title')) instead of using $_POST directly ($_POST['title']).[/quote]
I'm aware of this and I use Input Class myself. By writing $_POST I meant POST method in general.


Using $_POST at the model - El Forum - 08-13-2009

[eluser]urrus[/eluser]
[quote author="kirkaracha" date="1250124896"]The user guide recommends using the Input Class ($this->input->post('title')) instead of using $_POST directly ($_POST['title']).[/quote]

What is the benefit of this style?

Only cuz You get false in to variable when post item empty

$test=$this->input->post('test');

Or there is something else


Using $_POST at the model - El Forum - 08-13-2009

[eluser]Edmundas Kondrašovas[/eluser]
[quote author="urrus" date="1250185311"][quote author="kirkaracha" date="1250124896"]The user guide recommends using the Input Class ($this->input->post('title')) instead of using $_POST directly ($_POST['title']).[/quote]

What is the benefit of this style?

Only cuz You get false in to variable when post item empty

$test=$this->input->post('test');

Or there is something else[/quote]
The purpose of Input Class is clearly explained in the User Guide.

Quote:The Input Class serves two purposes:

1. It pre-processes global input data for security.
2. It provides some helper functions for fetching input data and pre-processing it.