Problem in codeigniter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bluemagix
Forum Newbie
Posts: 1
Joined: Thu Nov 20, 2008 3:44 am

Problem in codeigniter

Post by bluemagix »

I am getting an error as

Message: Undefined property: Category::$category_m

Fatal error: Call to a member function getNumCategory() on a non-object in C:\wamp\www\system\application\controllers\category.php on line 15

controllers\category.php

Code: Select all

 
class Category extends Controller{
    function Category(){    
        // load controller parent
        parent::Controller();
        // load 'Categorys' model
        $this->load->model('category_m','category');
        $this->load->database();
              $this->load->helper('url');
              $this->load->helper('form');
    }
 
    function index(){
        $this->load->database();
        $data['numCategory']=$this->Category_m->getNumCategory();
        $data['title']='Displaying Category data';
        $data['header']='Category List';
        // load 'Categorys_view' 
        $this->load->view('category_view',$data);
    }
}
 
models/category_m.php

Code: Select all

 
 
class Category_m extends Model{
    function Category_m(){    // call the Model constructor
        parent::Model();    // load database class and connect to MySQL
        $this->load->database();
    }
    // get all Category
    function getCategory(){
        $query=$this->db->get('category');
        if($query->num_rows()>0){    // return result set as an associative array
            return $query->result_array();
        }
    }
    // get total number of Category
    function getNumCategory(){
        return $this->db->count_all('category');
    }
}
 
I have tried everything and now exhausted
i have done autoload database also.


PLZZZZZZ help..
Post Reply