title: Zend Framework: Incomplete object error when passing a value from controller to view
body: <p>I'm passing a user object from the controller to the view, then calling a method on that controller.  I've done a print_r on the object in the view, so I know it's the right object with the right values.  The current_user variable is an instance of the user class.  </p>
  
  <p>Here is the line in the layout that gives the error.  </p>
  
  <pre><code>&lt;?php echo $this-&gt;current_user-&gt;get_avatar_url(); ?&gt;
  </code></pre>
  
  <p>Here is the method in the user class it's calling</p>
  
  <pre><code>public function get_avatar_url()
  {
      return !empty($this-&gt;avatar) ? $this-&gt;avatar : $this-&gt;fb_userid != '' ? "http://graph.facebook.com/".$this-&gt;fb_userid."/picture" : "/public/images/pukie.jpg";
  }
  </code></pre>
  
  <p>This is the error I get</p>
  
  <blockquote>
    <p><strong>Fatal error</strong>:  main() The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "User" of the object you are trying to operate on was loaded <em>before</em> unserialize() gets called or provide a __autoload() function to load the class definition  in <strong>/home/breathel/public_html/application/views/layouts/layout.phtml</strong> on line <strong>48</strong></p>
  </blockquote>
  
  <p>I'm including the full controller base where this in called in case it makes a difference</p>
  
  <pre><code>&lt;?php
  Zend_Loader::loadClass('Zend_Controller_Action');
  Zend_Loader::loadClass('User');
  
  class BaseController extends Zend_Controller_Action
  {
      protected $auth;
      protected $current_user;
      protected $db;
  
      protected function initialize_values()
      {
          $auth = Zend_Auth::getInstance();
          if($auth-&gt;hasIdentity())
          {
              $this-&gt;current_user = $auth-&gt;getIdentity();
              $this-&gt;view-&gt;current_user = $this-&gt;current_user;
          }
  
          $this-&gt;db = Zend_Registry::get('dbAdapter');
  
          $this-&gt;view-&gt;controller_name = $this-&gt;_request-&gt;getControllerName();
          $this-&gt;view-&gt;view_name = $this-&gt;_request-&gt;getActionName();
      }
  }
  </code></pre>