我正在尝试更改 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);
它成功地保存了 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();
}