Welcome Guest, Not a member yet? Register   Sign In
Filtering input - controller or model?
#1

[eluser]SpaceCoder[/eluser]
I have such model and controller for AJAX comment posting
model:
Code:
class Items_model extends Model {
function add_comment($item_id, $user_id, $text, $type)
    {
        $data = array(
            'item_id' => $item_id,
            'user_id' => $user_id,
            'text' => $text,
            'type' => $type,
            'created_at' => mktime()
        );
        $this->db->insert('comments', $data);
        return $this->db->insert_id();
    }

controller:
Code:
class Items extends Controller {
function add_comment()
    {
        $this->load->helper('date');
        
        $item_id = $this->input->post('item_id', TRUE);
        $text = $this->input->post('comment_text', TRUE);
        $type = $this->input->post('type', TRUE);

        $user_id = $this->session->userdata('user_id'); // user id, must be logged in
        
        $this->Items_model->add_comment($item_id, $user_id, $text, $type);
        $response = array(
            'message' => 'Thank you!'
        );
        echo json_encode($response);
    }

In controller or in model should I control that $item_id and $text are not null, $user_id is set and user has logged in?
And how?

Best, Kirill.


Messages In This Thread
Filtering input - controller or model? - by El Forum - 12-04-2010, 04:41 PM
Filtering input - controller or model? - by El Forum - 12-04-2010, 11:27 PM
Filtering input - controller or model? - by El Forum - 12-06-2010, 04:58 AM
Filtering input - controller or model? - by El Forum - 12-06-2010, 06:49 AM
Filtering input - controller or model? - by El Forum - 12-06-2010, 08:43 AM
Filtering input - controller or model? - by El Forum - 12-06-2010, 08:45 AM
Filtering input - controller or model? - by El Forum - 12-06-2010, 10:18 AM
Filtering input - controller or model? - by El Forum - 12-07-2010, 08:29 PM



Theme © iAndrew 2016 - Forum software by © MyBB