Zend_Auth storage and Models references map problem

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Zend_Auth storage and Models references map problem

vbogoev
This post was updated on .
Hello!

When I 'write' my Model_User in Zend_Storage the reference between Model_User and other Models are lost...

Here is my login plugin:

     /**
     * Check if authenication exists.
     * @return boolean
     */
    public function isValid()
    {
        if($this->_authAdapter->authenticate()->isValid())
        {
            $userModel = new Model_Users();
            $identify = $userModel->findByUsername($this->_username);

            $auth = Zend_Auth::getInstance();
            $storage = $auth->getStorage();
            $storage->write($identify);

            return true;
        }
        return false;
    }

Here is my Model_Row_User:

class Model_Row_User extends Zend_Db_Table_Row_Abstract
{
    protected $_preferences = null;
    static protected $_defaultPreferences = null;

    static function getDefaultPreferences()
    {
        if(self::$_defaultPreferences === null)
        {
            self::$_defaultPreferences = Model_UserPreferences::getDefaultPreferences();
        }
        return self::$_defaultPreferences;
    }

    public function __construct(array $config = array())
    {
        parent::__construct($config);
    }

    public function getPreferences($default = false)
    {
        if($default)
        {
            return (object)self::getDefaultPreferences();
        }
       
        if($this->_preferences == null)
        {
            $this->_preferences = $this->findDependentRowset('Model_UserPreferences', null, $this->select())->toArray();
            $this->_preferences = $this->_preferences[0];
           
            if(empty($this->_preferences))
            {
                $this->_preferences = self::getDefaultPreferences();
            }
        }
        return (object)$this->_preferences;
    }
}

Here is my controller:

public function init()
    {
        if(Zend_Auth::getInstance()->hasIdentity())
        {
            $this->_auth = Zend_Auth::getInstance()->getStorage()->read();
            Zend_Registry::set('currentUser', $this->_auth);
        }
        else
        {
            $this->_auth = null;
        }

        $this->view->auth = $this->_auth;
    }

public function catalogAction()
{
$this->_auth->getPreferences(); //throw exception... Fatal error: Call to a member function select() on a non-object in C:\xampp\htdocs\dem\library\Zend\Db\Table\Row\Abstract.php on line 418
}

When I dump $this->_auth in my controller, variable _table is empty. When I fetch the user in controller variable _table is normal.

Do you know where is the problem?

Thank you!
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Auth storage and Models references map problem

vbogoev
I found the problem.

After Zend_Auth::getInstance()->getStorage()->read(); I must set table to the Model_Row_User like that

$user = Zend_Auth::getInstance()->getStorage()->read();
$user->setTable(new Model_Users());

That's it! :)