0
votes

I am learning CodeIgniter and I started making my own website but I got these errors.

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Kategori::$kategori_model

Filename: admin/Kategori.php

Line Number: 13

Backtrace:

File: C:\xampp\htdocs\Geekindo\application\controllers\admin\Kategori.php Line: 13 Function: _error_handler

File: C:\xampp\htdocs\Geekindo\index.php Line: 315 Function: require_once

Kategori class

defined('BASEPATH') OR exit('No direct script access allowed');

class Kategori extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->load->model('Kategori_model');
    }
    public function index()
    {
        $kategori = $this->kategori_model->listing();
        $data = array(
            'title' => 'Kategori post',
            'header' => 'List kategori berita',
            'kategori' => $kategori,
            'isi' => 'kategori_post/list'
        );
        $this->load->view('admin/wrapper', $data, FALSE);
    }

}

Kategori_model class

defined('BASEPATH') OR exit('No direct script access allowed');

class Kategori_model extends CI_Model {


        public function __construct()
        {
            parent::__construct();
            $this->load->database();
        }

        public function listing()
        {
            $this->db->select('*');
            $this->db->from('kategori_post');
            $this->db->order_by('nama_kategori_post','desc');

            $query = $this->db->get();
            return $query->result_array();
        }
        public function get_by($id)     
        {
            $this->db->where('kategori_post_id', $id);
            $query = $this->db->get('kategori_post');
            return $query->row_array();
        }

}
2
I am not sure but is this, kategori_model => Kategori_model, try once!! - Rahul
It seems that your model isn't being loaded. Did your model file is named kategori_model.php and it is under the model's path ? - DontVoteMeDown
Did you also use subdirectories for your models? You'd need to load admin/kategori_model. Docs: Loading a Model: If your model is located in a sub-directory, include the relative path from your models directory. - FirstOne

2 Answers

0
votes

PHP is case sensitive,

 public function __construct()
    {
        parent::__construct();
        $this->load->model('Kategori_model');
    }

your code showing that you're load the Kategori_model in capital,

public function index()
    {
        $kategori = $this->kategori_model->listing();
    }

but when you calling the model, you aren't using the capital at the kategori_model.

i suggest you to change it into :

$kategori = $this->Kategori_model->listing();
0
votes

Try This Code

public function __construct(){
    parent::__construct();
    $this->load->model('Kategori_model','km');
}
public function index(){
    $kategori = $this->km->listing();
}