Form verilerini kontrol edin - model ya da kontrolöre?

0 Cevap php

In CodeIgniter, I comment posting with AJAX için böyle bir model ve denetleyici var

Model:

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();
    } 

denetleyicisi:

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 data from form: $item_id and $text are not null, $user_id is set and user has logged in? And how?

En iyisi, Kirill.

0 Cevap