0

I am working on zend module based structure for my project. As Zend_Auth class' default session storage is Zend_Auth. I changed according to module being called. Say for admin I use auth namespace Admin_Auth and for default module i use namespace name Default_Auth.

$auth = Zend_Auth::getInstance();
$auth->setStorage(new Zend_Auth_Storage_Session('Admin_Auth'));

I am doing this because, if I do Zend_Session::destroy() it will destroy complete session even for Default Module. and so using namespace and so at logout Zend_Session::namespaceUnset('Admin_Auth');

each time in different controller I have to use

$auth = Zend_Auth::getInstance();
$auth->setStorage(new Zend_Auth_Storage_Session('Admin_Auth'));

just to point corresponding session data.

I am considering to move it in module's Bootstrap.php like

protected function _initAuth(){

    $auth = Zend_Auth::getInstance();
    $auth->setStorage(new Zend_Auth_Storage_Session('Admin_Auth'));

    return $auth;
}

First, is that proper way? Second, If it is then how can I access the return value $auth of _initAuth() in each controller? Please

Rajan Rawal
  • 6,171
  • 6
  • 40
  • 62
  • 1
    This won't work, because module bootstraps are run on every request, so each module will replace the storage for the previous one. Why do you need different auth data for each module? – Tim Fountain Apr 19 '13 at 08:18
  • @TimFountain because when I set `$authStorage->write($identity);` these data become available for default module to. so I dont want default module to have those data – Rajan Rawal Apr 19 '13 at 09:10
  • Okay, but why? If it's an attempt to secure the session data, it's just being written to `$_SESSION`, so regardless of the namespace you use it will always be available to all PHP scripts running on your domain. – Tim Fountain Apr 19 '13 at 09:21
  • You could use a plugin with a `preDispatch()` hook that tests for the `moduleName` and sets storage as required. http://devzone.zend.com/1224/front-controller-plugins-in-zend-framework/ – RockyFord Apr 20 '13 at 08:23

0 Answers0