Welcome Guest, Not a member yet? Register   Sign In
POST data in model
#1

[eluser]maadmac[/eluser]
Quick question:

There shouldn't be any problem with invoking the Input class in a model, correct? Something like this:

Code:
<?php

class Test_model extends Model {

    function __construct() {
        parent::Model();
    }
    
    function test_function() {
        $this->session->set_userdata('some_data') = $this->input->post('some_data');
        }
?>

I've seen it in other posts in the forum, so I'm fairly sure it should work, but I was having some trouble earlier with empty variables and am wondering if it's related...
#2

[eluser]ELRafael[/eluser]
i don't think there is any problem.

i don't use. I prefer to leave in controller. If one day, the input in the view changes, i'll need to change in model. To me, model just access the base and executes query. Just this
#3

[eluser]maadmac[/eluser]
[quote author="ELRafael" date="1193444283"]i don't use. I prefer to leave in controller. If one day, the input in the view changes, i'll need to change in model. To me, model just access the base and executes query. Just this[/quote]

Hi ELRafael,

Got it, thanks. I think for me this is a SESSION issue more than a POST one, I guess I'm in the habit of handling all db queries AND session data handling in the model, since session info is just another kind of data model.

But I'm not sure I understand one point: if the input in the view changes, you'll have to change the controller, also, no? So you have to adapt the model or the controller, I don't see the difference.
#4

[eluser]ELRafael[/eluser]
in my case only controller.

in the model i don't pass anything about input... only vars!

So, if in my view
Code:
<input type="text" name="name">

And the controller
Code:
$name = $this->input->post('name');
$this->model_file->get_names($name);

Model
Code:
function get_names($_name)
{
  $this->db->where('name LIKE', $_name.'%');
  return $this->db->get('table');
}

See? My model is only to "talk" with database, like select, insert and others




Theme © iAndrew 2016 - Forum software by © MyBB