2013-01-01 40 views
3

我在我的應用程序中安裝了zfcuser模塊,一切正常。我配置了主機名路由器,這裏我的問題開始了,當我登錄主域(http://example.com)時,一切正常,但當我去任何子域(http://test.example.com,http://anysubdomain.example.com)我正在丟失記錄狀態,並且每個子域都必須重新登錄。如何跨子域共享登錄狀態?在ZF1中,我只是設置'cookie_domain',它的工作原理,但如何使它在ZF2?當然,我還使用Bjyauthorize,我想保持子域bjyauthorize衛士......如何在zend框架中跨子域共享zfcuser 2

回答

4

好,我找到的解決方案,在ZfcUser Module.php我說:

use Zend\Session\Config\SessionConfig; 
use Zend\Session\SessionManager; 
use Zend\Session\Container; 
use Zend\EventManager\EventInterface; 

public function onBootstrap(EventInterface $e) 
{ 
    $config = $e->getApplication() 
       ->getServiceManager() 
       ->get('Configuration'); 

    $sessionConfig = new SessionConfig(); 
    $sessionConfig->setOptions($config['session']); 
    $sessionManager = new SessionManager($sessionConfig); 
    $sessionManager->start(); 

    Container::setDefaultManager($sessionManager); 
} 

和ZfcUser模塊.config.php:

return array(
    'session' => array(
    'use_cookies' => true, 
    'cookie_domain'=>'example.com', 
) 
); 

希望它能幫助別人。