0

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.

Here is the line in the layout that gives the error.

<?php echo $this->current_user->get_avatar_url(); ?>

Here is the method in the user class it's calling

public function get_avatar_url()
{
    return !empty($this->avatar) ? $this->avatar : $this->fb_userid != '' ? "http://graph.facebook.com/".$this->fb_userid."/picture" : "/public/images/pukie.jpg";
}

This is the error I get

Fatal error: 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 before unserialize() gets called or provide a __autoload() function to load the class definition in /home/breathel/public_html/application/views/layouts/layout.phtml on line 48

I'm including the full controller base where this in called in case it makes a difference

<?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->hasIdentity())
        {
            $this->current_user = $auth->getIdentity();
            $this->view->current_user = $this->current_user;
        }

        $this->db = Zend_Registry::get('dbAdapter');

        $this->view->controller_name = $this->_request->getControllerName();
        $this->view->view_name = $this->_request->getActionName();
    }
}
6
  • The error talks about serialization but I don't see the line. Commented Nov 2, 2011 at 0:27
  • That's because I'm not serializing the object, it's definitely got me stumped. Commented Nov 2, 2011 at 0:44
  • 1
    I see that the error is in the layout, not in the view...can you check this? Commented Nov 2, 2011 at 0:48
  • You're correct, the line that displays the avatar is in the layout. Would that make a difference? Commented Nov 2, 2011 at 4:49
  • @Jhorra : Did you get this issue resolved Commented Mar 28, 2017 at 7:32

1 Answer 1

2

Zend Framework's authorisation module uses sessions to preserve identity across page load and is probably serialising the User model under the covers (especially if you're just assigning the result of a Zend_Auth_Adapter call).

Try including the User class before the first call to getIdentity() and see if that fixes it (even if you're confident you're not serialising it yourself).

Sign up to request clarification or add additional context in comments.

1 Comment

I've included the user file, but it still gives the error. I've also edited the post with the full controller base class where these values are set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.