Error undefined length, start, draw, search

Error undefined length, start, draw, search

mozikunmozikun Posts: 3Questions: 2Answers: 0

hi, i want to ask how to make server side datatables on codeigniter.

this my model php

[code]
class Manifest_in_m extends CI_Model{

var $table = "awb_incoming";
var $select_column = array("id", "no_awb", "air_line", "product");
var $order_column = array(null, "no_awb", "air_line", null, null);

function make_query()
{
   $this->db->select($this->select_column);
   $this->db->from($this->table);

   if(isset($_POST["search"]["value"]))
   {
        $this->db->like("no_awb", $_POST["search"]["value"]);
        $this->db->or_like("air_line", $_POST["search"]["value"]);
   }

   if(isset($_POST["order"]))  
   {  
        $this->db->order_by($this->order_column[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);  
   }
   else
   {
        $this->db->order_by('id', 'DESC');
   }
}

function make_datatables(){
   $this->make_query();
   if($_POST["length"] != -1)
   {
        $this->db->limit($_POST['length'], $_POST['start']);
   }
   $query = $this->db->get();
   return $query->result();
}

function get_filtered_data(){
   $this->make_query();
   $query = $this->db->get();
   return $query->num_rows();
}

function get_all_data()
{
   $this->db->select("*");
   $this->db->from($this->table);
   return $this->db->count_all_results();
}

}
[/code]

this the controller

[code]
class Manifest extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('manifest_in_m');
}

public function index()
{
    $this->load->view('manifest_incoming');
}

function fetch_user(){
   $this->load->model("manifest_in_m");
   $fetch_data = $this->manifest_in_m->make_datatables();
   $data = array();
   foreach($fetch_data as $row)
   {
        $sub_array = array();
        $sub_array[] = $row->no_awb;
        $sub_array[] = $row->air_line;
        $sub_array[] = $row->product;
        $data[] = $sub_array;
   }
   $output = array(
        "draw" => intval($_POST["draw"]),
        "recordsTotal" => $this->manifest_in_m->get_all_data(),
        "recordsFiltered" => $this->manifest_in_m->get_filtered_data(),
        "data" => $data
   );  
   echo json_encode($output);  

}

}
[/code]

i didn't create the view because i want to check my json first, but my json result like this

Message: Undefined index: length
Filename: models/Manifest_in_m.php
Line Number: 33

Message: Undefined index: length
Filename: models/Manifest_in_m.php
Line Number: 35

Message: Undefined index: start
Filename: models/Manifest_in_m.php
Line Number: 35

Message: Undefined index: draw
Filename: controllers/Manifest.php
Line Number: 30

i don't know why, but this is happend only for me, please help me, thank you

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    My guess is that since you are looking for $_POST variables, you haven't set the ajax.type option to be POST (the default is GET). Example available here.

    Allan

This discussion has been closed.