[eluser]Jow272[/eluser]
Hello all,
I keep getting errors when I instantiate a class in a controller. I can't figure out what I'm doing wrong.
I'm writing a web application in CI in which there are several types of addresses to be stored, like the address of a building, of a persons birth, death and more variations. As I want to store all addresses in one single table, it seems appropriate to me to use a specialised address controller and address model to handle the functions related to the addresses. So I did the following:
address.php;
Code:
class Address extends MY_Controller{
// private fields
private $m_id;
private $m_street;
...
// constructor
function __construct($address = NULL)
{
// load the parent controller
parent::Controller();
$this->load->model('address_model');
// set the private fields
if ( $address != NULL )
{
$this->m_street = $address->street;
...
}
}
public function create()
{
// create a new address
...
}
public function check_if_address_is_known($address = NULL)
{
// check if the address is already stored in the address table
...
}
}
example caller i.php:
Code:
include_once("address.php");
class I extends MY_Controller{
// constructor
function __construct($address = NULL)
{
// load the parent controller
parent::Controller();
$this->load->model('i_model');
}
public function create($data)
{
$address_controller = new Address($data);
$address_id = $address_controller->check_if_address_is_known();
...
}
}
Running the code produces a php error "Undifined property: Address::$i_model", Filename "libraries/Loader.php", Line NUmber: 1035.
This error is caused by the instantiating of the address class.
Anyone any idea's? Thanx in advance!