How does the Zend_Auth repository work?

It is very simple. I write

$auth->getStorage()->write($user);

And then I want to load this $ user in a separate process, but I cannot, because

$user = $auth->getIdentity();

is empty. Aren't I just ... INSTALLING? Why is this not working? Halp?

[EDIT 2011-04-13]

This was requested almost two years ago. The fact, however, is that I repeated this question in July 2010 and received a fantastic answer, which I simply did not understand then.

Link: Zend_Auth cannot write to storage

Since then I have created a very nice litte class that I use (sometimes with additional customization) in all my projects, using the same storage mechanism as Zend_Auth, but bypassing all the bad ones.

<?php

class Qapacity_Helpers_Storage {

    public function save($name = 'default', $data) {

        $session = new Zend_Session_Namespace($name);
        $session->data = $data;

        return true;
    }

    public function load($name = 'default', $part = null) {

        $session = new Zend_Session_Namespace($name);

        if (!isset($session->data))
            return null;

        $data = $session->data;

        if ($part && isset($data[$part]))
            return $data[$part];

        return $data;
    }

    public function clear($name = 'default') {

        $session = new Zend_Session_Namespace($name);

        if (isset($session->data))
            unset($session->data);

        return true;
    }

}

?>
+5
source share
3

.

Auth getIdentity.

/**
 * Returns the identity from storage or null if no identity is available
 *
 * @return mixed|null
 */
public function getIdentity()
{
    $storage = $this->getStorage();

    if ($storage->isEmpty()) {
        return null;
    }

    return $storage->read();
}

PHP Session Storage:

/**
 * Defined by Zend_Auth_Storage_Interface
 *
 * @return mixed
 */
public function read()
{
    return $this->_session->{$this->_member};
}

/**
 * Defined by Zend_Auth_Storage_Interface
 *
 * @param  mixed $contents
 * @return void
 */
public function write($contents)
{
    $this->_session->{$this->_member} = $contents;
}

, Zend_Auth?

$auth = Zend_Auth::getInstance();

, write getIdentity?

, , , , .

+1

, , ? ? Cookies, session.cookie_domain ini.

, cookie PHPSESSID, ? ?

, , . , ini session.save_path. , PHPSESSID, ?

root@ip-10-226-50-144:~# less /var/lib/php5/sess_081fee38856c59a563cc320899f6021f 
foo_auth|a:1:{s:7:"storage";a:1:{s:9:"user_id";s:2:"77";}}
0

register_shutdown_function('session_write_close');

to index.php :

$application->bootstrap()->run();
0

All Articles