[eluser]dbug[/eluser]
I am new to code ignitor and mvc in general. I am having an issue when I try to use a class inside another class to access their model I get a database error.
---------------
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Catalog_helper::$db
Filename: core/Model.php
Line Number: 50
Fatal error: Call to a member function query() on a non-object in /opt/bitnami/apache2/htdocs/codeigniter/application/models/catalog_model.php on line 11
----------------
Code example of what I am trying to do. I might be going about it the incorrect way.
helper class:
class Catalog_helper extends CI_Controller {
function __construct() {
parent::__construct();
$this->view_data['base_url'] = base_url();
$this->load->model('Catalog_model');
}
function get_catalog(){
// query catalog model return data to view
$catalog_data = $this->Catalog_model->return_catalog_data();
$data["json"] = json_encode($catalog_data);
echo $data["json"];
}
}
Catalog model:
class Catalog_model extends CI_Model {
function __construct() {
parent::__construct();
}
function return_catalog_data(){
$query_str = "SELECT * FROM catalog";
$result = $this->db->query($query_str);
return $result->result_array();
}
}
class using helper:
class Inventory extends CI_Controller {
function __construct() {
parent::__construct();
$this->view_data['base_url'] = base_url();
$this->load->model('Inventory_model');
}
function test_helper(){
$this->load->helper('Catalog_helper');
$catalog = new Catalog_helper;
//var_dump($catalog);
$catalog->get_catalog();
}
}
What could be causing this php error? Thanks if you have any advice.