Problem loading data with flexigrid in codeigniter 3.0

85 Views Asked by At

I want to load data from my database into the flexigrid. But when I tried to load the data, the error showed the message

Methods with the same name as their class will not be constructors in a future version of PHP; Flexigrid has a deprecated constructor

here is my controller:

public function index()
{
    if($this->session->userdata('logged_in'))
    {
        $this->lists();
    }else{
        redirect('c_index');
    }
}

public function lists(){
    //load flexigrid setting
    $colModel['branch_id'] = array('NAMA PENGGUNA',60,TRUE,'left',2);
    $colModel['login_id'] = array('NIK',100,TRUE,'left',2);
    $colModel['login_name'] = array('NAMA',150,TRUE,'left',2);
    $colModel['email_add'] = array('ROLE',150,TRUE,'left',2);
    $colModel['EmployeePositionID'] = array('ROLE',150,TRUE,'left',2);

    $colModel['aksi'] = array('AKSI',60,FALSE,'center',2);

    //Populate flexigrid buttons
    $buttons[] = array('Select All','check','btn');
    $buttons[] = array('separator');
    $buttons[] = array('DeSelect All','uncheck','btn');
    $buttons[] = array('separator');
    $buttons[] = array('Add','add','btn');
    $buttons[] = array('separator');
    $buttons[] = array('Delete Selected Items','delete','btn');
    $buttons[] = array('separator');

    $gridParams = array(
        'height' => 300,
        'rp' => 10,
        'rpOptions' => '[10,20,30,40]',
        'pagestat' => 'Displaying: {from} to {to} of {total} items.',
        'blockOpacity' => 0.5,
        'title' => '',
        'showTableToggleBtn' => false
    );

    $grid_js = build_grid_js('flex1',site_url('spvcoll/c_sample/load_data'),$colModel,'no','asc',$gridParams,$buttons);

    $data['js_grid'] = $grid_js;

    //load page attribute
    $data['utama'] = $this->load->view('spvcoll/v_list',$data,TRUE);
    $data['judul'] = 'List Assign';

    $this->load->view('v_index', $data);
}

public function load_data(){
    $this->load->library('flexigrid');
    $valid_fields = array('branch_id','login_id','login_name','email_add','EmployeePositionID');

    $this->flexigrid->validate_post('login_id','ASC',$valid_fields);
    $records = $this->m_spvcoll->GetData();

    $this->output->set_header($this->config->item('json_header'));

    $record_items = array();
    $counter=0;
    foreach ($records['records']->result() as $row)
    {
        $counter++;
        $record_items[] = array(
            $row->id_pengguna,
            $row->nama_pengguna,
            $row->nik,
            $row->nama,
            $row->no_telepon,
            $row->role,
            '<button type="submit" class="btn btn-default btn-xs" title="Edit" onclick="edit_user(\''.$row->id_pengguna.'\')"/><i class="fa fa-pencil"></i></button>'
//          '<i class="fa fa-user fa-fw"></i> <input type="button" value="Edit" class="ubah btn btn-info btn-xs" onclick="edit_user(\''.$row->nama_pengguna.'\')"/>'
//          '<input type="button" value="Reset" class="ubah" onclick="edit_user(\''.$row->nama_pengguna.'\')"/>'
        );  
    }
    //Print please
    $this->output->set_output($this->flexigrid->json_build($records['record_count'],$record_items));
}

and this is my model:

public function GetData($username, $password){
    //Build contents query
    $this->db->select('*')->from($this->_table);
    $this->CI->flexigrid->build_query();

    //Get contents
    $return['records'] = $this->db->get();

    //Build count query
    $this->db->select("count(login_name) as record_count")->from($this->_table);
    $this->CI->flexigrid->build_query(FALSE);
    $record_count = $this->db->get();
    $row = $record_count->row();

    //Get Record Count
    $return['record_count'] = $row->record_count;

    //Return all
    return $return;
}
1

There are 1 best solutions below

0
DFriend On

You seem to have created a library file named "Flexigrid.php" for creating a class of the same name, e.g.

class Flexigrid {

Somewhere in that class, you have created a method with the same name, e.g.

public function flexigrid()
{
     ...
}

The name of the function flexigrid should probably be changed. If it is the function that creates a new instance of the class the new name should be __construct. Otherwise, it can be called whatever you like.