Welcome Guest, Not a member yet? Register   Sign In
CI and instantiating classes
#1

[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!


Messages In This Thread
CI and instantiating classes - by El Forum - 11-21-2009, 08:31 AM
CI and instantiating classes - by El Forum - 11-21-2009, 10:17 AM
CI and instantiating classes - by El Forum - 11-21-2009, 11:10 AM
CI and instantiating classes - by El Forum - 11-21-2009, 11:58 AM
CI and instantiating classes - by El Forum - 11-21-2009, 12:21 PM
CI and instantiating classes - by El Forum - 11-21-2009, 12:43 PM
CI and instantiating classes - by El Forum - 11-22-2009, 03:54 AM
CI and instantiating classes - by El Forum - 11-22-2009, 06:28 AM
CI and instantiating classes - by El Forum - 11-22-2009, 06:50 AM
CI and instantiating classes - by El Forum - 11-22-2009, 09:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB