我试图改变Zend_Auth的会话后端.但不能成功.
在我的bootstrap.PHP
在我的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);
它正在保存值memcache成功没有问题.我测试
- $namespace = new Zend_Session_Namespace();
- $namespace->name = "Fatih";
在其他控制器
- $ns = new Zend_Session_Namespace();
- var_dump($ns->name);
没关系,但是我不能在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 } } }
在这里可以看到我的登录方式;
- 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();
- }
我不知道这是否会有任何帮助,但Zend_auth会自动创建您可以从任何地方访问的存储空间
- $session = new Zend_Session_Namespace('Zend_Auth');
- $session->storage->//here goes your property like user id password etc
现在如果使用Zend_Auth,它将使用Zend_Auth_Storage_Session默认值为“Zend_Auth”作为Zend_Session_Namespace.现在要更改所使用的命名空间,修改Zend_Auth_Storage_Session中的默认值,否则,如果要缓存此信息或将其存储在其他位置,您可以手动将其全部移动,并将其移动到所需位置.
现在我希望我帮助,但我不知道任何内存缓存