title: YII Fatal Error: Call To A Member Function Of A Non Object
body: <p>anyone can help me?
  I got stuck of this code.</p>
  
  <pre><code>$billing-&gt;bookingHeader-&gt;getCodeNumber('BKG');
  </code></pre>
  
  <p>Actually $billing is a model and bookingHeader is the relation.</p>
  
  <p>this line generate error</p>
  
  <pre><code>Fatal error: Call to a member function getCodeNumber() on a non-object
  </code></pre>
  
  <p>Below is the component contains result.</p>
  
  <pre><code>class MonthlyTransactionActiveRecord extends ActiveRecord
  {
  
      public function getCodeNumber($cnConstant = '')
      {
          $arr = array('I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI', 'XII');
          $month = $this-&gt;cn_month ? $this-&gt;cn_month - 1 : 0;
          return sprintf('%02d/%04d/%s/%s/%02d', $this-&gt;hotel_id, $this-&gt;cn_ordinal, $cnConstant, $arr[$month], $this-&gt;cn_year);
      }
  }
  </code></pre>
  
  <p>I call <code>$billing-&gt;bookingHeader-&gt;getCodeNumber('BKG');</code> twice (in view and controller), it has no error in view, but when I call it in Controller, it gives me error.</p>
  
  <p>What kind of trigger the error has? How to fix that?
  Thank you..</p>