Welcome Guest, Not a member yet? Register   Sign In
Error oin connecting the data base
#1

[eluser]Bluemagix[/eluser]
I am getting an error as

Message: Undefined property: Category::$category

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

controllers\category.php
Code:
class Category extends Controller{
    function Category(){    
        // load controller parent
        parent::Controller();
        // load 'Category model
        $this->load->model('category_m');
        $this->load->database();
    }

    function index(){
        $this->load->database();
        $data['category']=$this->category->getAllCategory();
        $data['numCategory']=$this->Category->getNumCategory();
        $data['title']='Displaying Category data';
        $data['header']='Category List';
        // load 'Categorys_view'
        $this->load->view('category_view',$data);
    }
}

models/category_m.php
Code:
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..
#2

[eluser]fensen[/eluser]
Please change:
Code:
$this->category->getAllCategory();
for
Code:
$this->category_m->getAllCategory();

also, the function getAllCategory() doesn't exist in the model you posted.
#3

[eluser]Bluemagix[/eluser]
If i remove the line getAllCategory() and
change like this

$data['numCategory']=$this->Category_m->getNumCategory();

then also i found the same error

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

the only difrance is

Message: Undefined property: Category::$Category_m
#4

[eluser]fensen[/eluser]
Please use "$this->category_m" lower case.

Once your model is loaded you can access it using the lower case version.

This should solve your problem.




Theme © iAndrew 2016 - Forum software by © MyBB