将Zend_Auth存储后端$ _SESSION更改为Memcached

Fat*_*mez 14 php zend-framework zend-auth zend-session

我正在尝试更改Zend_Auth的会话后端.但无法成功.在我的bootstrap.php;

    $oBackend = new Zend_Cache_Backend_Libmemcached(
        array(
            'servers' => $servers,
            'compression' => false
    ) );

    // configure caching frontend strategy
    $oFrontend = new Zend_Cache_Core(
        array(
            'caching' => true,
            'automatic_serialization' => true
        ) );

    // build a caching object
    $cache = Zend_Cache::factory( $oFrontend, $oBackend );

    $saveHandler = new \Application\Auth\Adapter\Memcached();
    $saveHandler->setCacher($cache);

    \Zend_Session::setSaveHandler($saveHandler);
Run Code Online (Sandbox Code Playgroud)

它成功地保存了值memcache没有问题.我测试一下;

    $namespace = new Zend_Session_Namespace();
    $namespace->name = "Fatih";
Run Code Online (Sandbox Code Playgroud)

在其他控制器;

    $ns = new Zend_Session_Namespace();
    var_dump($ns->name);
Run Code Online (Sandbox Code Playgroud)

没关系,但我在memcache中看不到Zend_Auth值.但是如果var_dump($_SESSION) 我能看到它就像;

["Zend_Auth"]=> array(1) { ["storage"]=> object(Application_Security_Auth_Storage)#66 (1) { ["_user":protected]=> object(Application_Security_Auth_User)#84 (4) { ["id":protected]=> object(MongoId)#87 (1) { ["$id"]=> string(24) "4fcca6b8c863c79d33000004" } ["username":protected]=> string(5) "admin" ["role":protected]=> string(5) "admin" ["fullname":protected]=> NULL } } }
Run Code Online (Sandbox Code Playgroud)

在这里你可以看到我的登录方法;

public function login($username, $password)
{
    if ($username == "" || $password == "")
        return false;

    $adapter = new \Application_Security_Auth_Adapter();

    $adapter->setIdentity($username);
    $adapter->setCredential($password);

    $auth = \Zend_Auth::getInstance();
    $result = $auth->authenticate($adapter);

    return $result->isValid();
}
Run Code Online (Sandbox Code Playgroud)

zar*_*ior 1

我不知道这是否有任何帮助,但是 Zend_auth 会自动创建您可以从任何地方访问的存储内容

$session = new Zend_Session_Namespace('Zend_Auth');
$session->storage->//here goes your property like user id password etc
Run Code Online (Sandbox Code Playgroud)

现在,如果您使用 Zend_Auth,它将使用 Zend_Auth_Storage_Session 默认值“Zend_Auth”作为 Zend_Session_Namespace。现在要更改使用的命名空间,请修改 Zend_Auth_Storage_Session 中的默认值,否则如果您想缓存此信息或将其存储在其他地方,则可以手动执行所有操作,您可以随时访问它并将其移动到您想要的位置。

现在我希望我能有所帮助,但我对内存缓存一无所知