I have controller that has error whenever i run it. I've Checked over and over again but can't find where is the mistake. the error is :
A PHP Error was encounteredSeverity: Notice
Message: Undefined property: Assetfilter::$Assetfiltermdl
Filename: controllers/Assetfilter.php
Line Number: 29
Fatal error: Call to a member function get_listkary() on a non-object in C:\wamp\www\asset_apps
\application\controllers\Assetfilter.php on line 29
Please Help.
This is my controller :
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Assetfilter extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('user');
$this->load->model('assetfiltermdl');
$this->load->model('worklistmdl');
$this->load->helper('url');
$this->load->helper('date');
$this->load->library('session');
$this->load->library('email');
$this->load->model('email_ctrl');
$this->datauser = $this->session->userdata('logged_id');
$this->load->library('form_validation');
$this->load->library('My_PHPMailer');
//Do your magic here
}
//update 20 oct 2016 list kary.
public function kary_reload()
{
$list = $this->Assetfiltermdl->get_listkary();
$data = array();
$no = $_POST['start'];
foreach ($list as $listkary) {
$no++;
$row = array();
$row[] = $listkary->$idnik;
$row[] = $listkary->kodenik;
$row[] = $listkary->namakary;
$row[] = $listkary->namaper;
$row[] = $listkary->iddept;
$row[] = $listkary->jabatan;
$row[] = $listkary->flagstatus;
$row[] = '<a href="<?php echo base_url(' . "'" . 'asset/karyawandetailform' . "'" .'); ?>/<?php echo $listkary[' . "'" . 'idnik' . "'" . '] ; ?>" class="btn btn-primary"> Detail</a>
<a href="<?php echo base_url(' . "'" . 'asset/karyawaneditform' . "'" . '); ?>/<?php echo $listkary[' . "'" . 'idnik' . "'" .'] ; ?>" class="btn btn-primary">Detail</a>
<a href="<?php echo base_url(' . "'" . 'asset/karyawandeleform' . "'" . '); ?>/<?php echo $listkary[' . "'" . 'idnik' . "'" .'] ; ?>" class="btn btn-primary" onClick="javascript:return confirm(' . "'" . 'Apakah Anda Sudah Yakin ?' . "'" . ')" >Del</a>';
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->assetfiltermdl->count_all(),
"recordsFiltered" => $this->assetfiltermdl->count_filtered(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}
}
This Is My Model:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Assetfiltermdl extends CI_Model {
var $kary_table = 'listkary';
var $kary_column_order = array(null, 'update_date'); //set column field database for datatable orderable
var $kary_column_search = array('idper','iddept','namakary','kodenik'); //set column field database for datatable searchable
var $kary_order = array('update_date' => 'desc'); // default order
public function __construct()
{
parent::__construct();
}
//update 20 oct 2016
public function get_listkary()
{
$this->_get_listkary_query();
echo $this->db->last_query();
//if($_POST['length'] != -1)
//$this->db->limit($_POST['length'], $_POST['start']);
$query = $this->db->get();
echo $this->db->last_query();
return $query->result();
}
private function _get_listkary_query()
{
//add custom filter here
if($this->input->post('idper'))
{
$this->db->where('idper', $this->input->post('idper'));
}
if($this->input->post('iddept'))
{
$this->db->where('iddept', $this->input->post('iddept'));
}
//if($this->input->post('idsubdept'))
//{
// $this->db->like('LastName', $this->input->post('LastName'));
//}
if($this->input->post('kodenik'))
{
$this->db->like('kodenik', $this->input->post('kodenik'));
}
if($this->input->post('namakry'))
{
$this->db->like('namakary', $this->input->post('namakry'));
}
$this->db->from($this->kary_table);
$i = 0;
foreach ($this->kary_column_search as $item) // loop column
{
if($_POST['search']['value']) // if datatable send POST for search
{
if($i===0) // first loop
{
$this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
$this->db->where($item, $_POST['search']['value']);
}
else
{
if($i===1) // second loop (iddept)
{
$this->db->where($item, $_POST['search']['value']);
}
else
{
$this->db->like($item, $_POST['search']['value']);
}
}
if(count($this->kary_column_search) - 1 == $i) //last loop
$this->db->group_end(); //close bracket
}
$i++;
}
}
public function count_all()
{
$this->db->from($this->kary_table);
return $this->db->count_all_results();
}
function count_filtered()
{
$this->_get_listkary_query();
$query = $this->db->get();
return $query->num_rows();
}
}
/* End of file assetfiltermdl.php */
/* Location: ./application/models/assetfiltermdl.php */
and this is my view :
<div class="right_col" role="main">
<div class="">
<div class="page-title">
<div class="title_left">
<h1> Data Karyawan </h1>
<h2> Informasi Data Karyawan </h2>
<p>
<a href ="<?php echo base_url('asset/karyawantambahform'); ?>" class="btn btn-primary">Tambah Karyawan Baru</a>
</p>
</div>
</div>
<div class="clearfix"></div>
<div class = "row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>Daftar Karyawan</h2>
<ul class="nav navbar-right panel_toolbox">
<li><a href="#"><i class="fa fa-chevron-up"></i></a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
</li>
<li><a href="#"><i class="fa fa-close"></i></a>
</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="x_content">
<form id="form-filter" class="form-horizontal">
<div class="item form-group">
<label for="idper" class="col-sm-2 control-label">Perusahaan</label>
<div class="col-sm-4">
<select class="select2_single form-control" tabindex="-1" id="idper" name="idper">
<option>Pilih Perusahaan</option>
<?php foreach ($perushlov as $key => $value) { ?>
<option value="<?php echo $value['idper']?>"><?php echo $value['namaper']?></option>}
<?php } ?>
</select>
</div>
</div>
<div class="item form-group" >
<label for="iddept" class="col-sm-2 control-label">Departemen :</label>
<div class="col-sm-4">
<select class="select2_single form-control" tabindex="-1" id="iddept" name="iddept">
<option >Pilih Departement</option>
<?php foreach ($deptlov as $key => $value) { ?>
<option value="<?php echo $value['iddept']?>"><?php echo $value['kodedept'] . ' - ' . $value['namadept'] . ' - ' . $value['namaper'] ?></option>}
<?php } ?>
</select>
</div>
</div>
<div class="item form-group">
<label for="kodenik" class="col-sm-2 control-label">Nama Karyawan</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="namakry">
</div>
</div>
<div class="item form-group">
<label for="kodenik" class="col-sm-2 control-label">Kode NIK</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="kodenik">
</div>
</div>
<div class="item form-group">
<label for="LastName" class="col-sm-2 control-label"></label>
<div class="col-sm-4">
<button type="button" id="btn-filter" class="btn btn-primary">Filter</button>
<button type="button" id="btn-reset" class="btn btn-default">Reset</button>
</div>
</div>
</form>
<!-- <table id="datatable-buttons" class="table table-striped table-bordered"> -->
<table id="master_karyawan" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>Id</th>
<th>Kode Nik</th>
<th>Nama Karyawan</th>
<th>Perusahaan</th>
<th>Departemen</th>
<th>Jabatan</th>
<th>Aktif</th>
<th>Administrasi</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var table;
$(document).ready(function() {
//datatables
table = $('#master_karyawan').DataTable({
"processing": true, //Feature control the processing indicator.
"serverSide": true, //Feature control DataTables' server-side processing mode.
"order": [], //Initial no order.
// Load data for the table's content from an Ajax source
"ajax": {
"url": "<?php echo base_url('index.php/Assetfilter/kary_reload')?>",
"type": "POST",
"data": function ( data ) {
data.perush = $('#idper').val();
data.depart = $('#iddept').val();
data.namakry = $('#namakry').val();
data.kodenik = $('#kodenik').val();
}
},
//Set column definition initialisation properties.
"columnDefs": [
{
"targets": [ 0 ], //first column / numbering column
"orderable": false, //set not orderable
},
],
});
$('#btn-filter').click(function(){ //button filter event click
table.ajax.reload(null,false); //just reload table
});
$('#btn-reset').click(function(){ //button reset event click
$('#form-filter')[0].reset();
table.ajax.reload(null,false); //just reload table
});
});
</script>
$list = $this->Assetfiltermdl->get_listkary();
I think this is your line number 29. May be you mentioned the caps A, that's why it is showing the error. – kishor10decho
lines from model. – Tpojka