Postingan lainnya
Muncul pesan kesalahan : A PHP Error was encountered Severity: Notice Message: Undefined property:
public function __construct()
{
parent::__construct();
$this->load->model('mahasiswa_model');
$this->load->library('form_validation');
}
//VIEW (index)
<form action="" method="POST">
<div class="input-group mt-1 mb-1">
<input type="text" class="form-control" name="keyword" placeholder="Cari....">
<div class="input-group-append">
<button class="btn btn-primary" type="submit">Cari</button>
</div>
</div>
</form>
//Controller (index)
public function index()
{
$data['judul'] = 'Halaman Mahasiswa';
$data['mahasiswa'] = $this->mahasiswa_model->getallmahasiswa();
if ($this->input->post('keyword')) {
$data['mahasiswa'] = $this->Mahasiswa_model->cari();
}
$this->load->view('templates/header', $data);
$this->load->view('mahasiswa/index', $data);
$this->load->view('templates/footer');
}
// Model ( cari() )
public function cari()
{
$keyword = $this->input->post('keyword', true);
$this->db->like('nama', $keyword);
return $this->db->get('tabel_mahasiswa')->result_array();
}
//mohon solusi....masih belajar CI
1 Jawaban:
<div>coba pemanggilan nama modelnya disamakan, pakai mahasiswa_model atau Mahasiswa_model ?<br>Perhatikan potongan kode ini : </div><pre> public function index() {
$data['judul'] = 'Halaman Mahasiswa';
$data['mahasiswa'] = $this-&gt;mahasiswa_model-&gt;getallmahasiswa(); //baris ini menggunakan mahasiswa_model
if ($this-&gt;input-&gt;post('keyword')) {
$data['mahasiswa'] = $this-&gt;Mahasiswa_model-&gt;cari(); //baris ini menggunakan Mahasiswa_model
}
$this-&gt;load-&gt;view('templates/header', $data);
$this-&gt;load-&gt;view('mahasiswa/index', $data);
$this-&gt;load-&gt;view('templates/footer');
}</pre>