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

[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?
#2

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

[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...
#4

[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?
#5

[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-gui....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.
#6

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

[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.
#8

[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.
#9

[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
#10

[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.




Theme © iAndrew 2016 - Forum software by © MyBB