Hi there, please help me to solve this problem.
This is my Controller code :
class welcome extends CI_Controller {
function __construct(){
parent::__construct();
}function index(){
//use this for your homepage
$data['title']= "Welcome to claudia's kids";
$data['navlist']=$this->MCats->getAllCategoriesNav();
$this->load->vars($data);
$this->load->view('template');
}
This controller trying to load this model. This is my Model code :
class MCats extends CI_Model {
function __construct(){
parent::__construct();
}
function getAllCategoriesNav(){
$data=array();
$Q=$this->db->get('categories');
if($Q->num_rows()>0){
foreach ($Q->result_array() as $row){
$data[$row['id']]=$row['name'];
}
}
$Q->free_result();
return $data;
}
}
Then i am entering the database configuration and change code in config/autoload.php
This is the code before :
/* | ------------------------------------------------------------------- | Auto-load Libraries | ------------------------------------------------------------------- | These are the classes located in the system/libraries folder | or in your application/libraries folder. | | Prototype: | | $autoload['libraries'] = array('database', 'session', 'xmlrpc'); */$autoload[‘libraries’] = array(’‘);
then i change the code something like this :
/* | ------------------------------------------------------------------- | Auto-load Libraries | ------------------------------------------------------------------- | These are the classes located in the system/libraries folder | or in your application/libraries folder. | | Prototype: | | $autoload['libraries'] = array('database', 'session', 'xmlrpc'); */$autoload[‘libraries’] = array(‘database’);
And I already have set the database configuration like this :
$active_group = ‘default’;
$active_record = TRUE;$db[‘default’][‘hostname’] = ‘localhost’;
$db[‘default’][‘username’] = ‘root’;
$db[‘default’][‘password’] = ‘wicaksono’;
$db[‘default’][‘database’] = ‘shoppingcart’;
$db[‘default’][‘dbdriver’] = ‘mysql’;
$db[‘default’][‘dbprefix’] = ‘’;
$db[‘default’][‘pconnect’] = TRUE;
$db[‘default’][‘db_debug’] = TRUE;
$db[‘default’][‘cache_on’] = FALSE;
$db[‘default’][‘cachedir’] = ‘’;
$db[‘default’][‘char_set’] = ‘utf8’;
$db[‘default’][‘dbcollat’] = ‘utf8_general_ci’;
$db[‘default’][‘swap_pre’] = ‘’;
$db[‘default’][‘autoinit’] = TRUE;
$db[‘default’][‘stricton’] = FALSE;
Then here is the errors show on browsers :
A PHP Error was encountered
Severity: Notice
Message: Undefined property: welcome::$MCats
Filename: controllers/welcome.php
Line Number: 11
Fatal error: Call to a member function getAllCategoriesNav() on a non-object in C:\xampplite\htdocs\xampp\shopping\application\controllers\welcome.php on line 11