title: codeIgniter error: Undefined property
body: <p>A PHP Error was encountered</p>
  
  <blockquote>
    <p>Severity: Notice</p>
    
    <p>Message: Undefined property: Magazine::$db</p>
    
    <p>Filename: core/Model.php</p>
    
    <p>Line Number: 52</p>
  </blockquote>
  
  <hr>
  
  <pre><code>&lt;?php
  
      class MY_Model extends CI_Model {
          const DB_TABLE = 'abstract';
          const DB_TABLE_PK = 'abstract';
  
  
          function __construct(){
              parent::__construct(); // construct the Model class
          }
          /**
           * Create record.
           */
          private function insert() {
              $this-&gt;db-&gt;insert($this::DB_TABLE, $this);
              $this-&gt;{$this::DB_TABLE_PK} = $this-&gt;db-&gt;insert_id();
          }
  
          /**
           * Update record.
           */
          private function update() {
              $this-&gt;db-&gt;update($this::DB_TABLE, $this, $this::DB_TABLE_PK);
          }
  
          /**
           * Populate from an array or standard class.
           * @param mixed $row
           */
          public function populate($row) {
              foreach ($row as $key =&gt; $value) {
                  $this-&gt;$key = $value;
              }
          }
  
          /**
           * Load from the database.
           * @param int $id
           */
          public function load($id) {
              $query = $this-&gt;db-&gt;get_where($this::DB_TABLE, array(
                  $this::DB_TABLE_PK =&gt; $id,
              ));
              $this-&gt;populate($query-&gt;row());
          }
  
          /**
           * Delete the current record.
           */
          public function delete() {
              $this-&gt;db-&gt;delete($this::DB_TABLE, array(
                 $this::DB_TABLE_PK =&gt; $this-&gt;{$this::DB_TABLE_PK}, 
              ));
              unset($this-&gt;{$this::DB_TABLE_PK});
          }
  
          /**
           * Save the record.
           */
          public function save() {
              if (isset($this-&gt;{$this::DB_TABLE_PK})) {
                  $this-&gt;update();
              }
              else {
                  $this-&gt;insert();
              }
          }
  
          /**
           * Get an array of Models with an optional limit, offset.
           * 
           * @param int $limit Optional.
           * @param int $offset Optional; if set, requires $limit.
           * @return array Models populated by database, keyed by PK.
           */
          public function get($limit = 0, $offset = 0) {
              if ($limit) {
                  $query = $this-&gt;db-&gt;get($this::DB_TABLE, $limit, $offset);
              }
              else {
                  $query = $this-&gt;db-&gt;get($this::DB_TABLE);
              }
              $ret_val = array();
              $class = get_class($this);
              foreach ($query-&gt;result() as $row) {
                  $model = new $class;
                  $model-&gt;populate($row);
                  $ret_val[$row-&gt;{$this::DB_TABLE_PK}] = $model;
              }
              return $ret_val;
          }
      }
      ?&gt;
  </code></pre>
  
  <hr>
  
  <p>and my controller is the next one </p>
  
  <hr>
  
  <pre><code>&lt;?php
  if ( ! defined("BASEPATH") ) exit("No direct script access allowed");
  
  class Magazine extends CI_Controller {
  
   public function index(){
  
       $this-&gt;load-&gt;model('Publication');
       $this-&gt;Publication-&gt;publication_name = 'Sandy Shore';
       $this-&gt;Publication-&gt;save();
       echo '&lt;tt&gt;&lt;pre&gt;' .  var_export( $this-&gt;Publication, TRUE) . '&lt;/pre&gt;&lt;/tt&gt;';
  
       $this-&gt;load-&gt;model('Issue');
       $issue = new Issue();
       $issue-&gt;publication_id = $this-&gt;Publication-&gt;publication_id;
       $issue-&gt;issue_number=2;
       $issue-&gt;issue_date_publication = date('2015-04-21');
       $issue-&gt;save();
       echo '&lt;tt&gt;&lt;pre&gt;' .  var_export( $issue, TRUE) . '&lt;/pre&gt;&lt;/tt&gt;';
  
       $this-&gt;load-&gt;view('magazines');   
   }    
  
  
  }
  </code></pre>