Zend_Auth会话在路由到子域时不可用但是在我退出之前可以使用没有子域的其他页面,这是我在ACL中用于路由到子域的代码。以example.com/index身份登录后,在访问subdomain.example.com时,已登录用户的会话或身份验证身份未获得。
public function preDispatch(Zend_Controller_Request_Abstract $request) {
$module = $request->getModuleName();
$resource = $request->getControllerName();
$action = $request->getActionName();
$params = $request->getParams();
try {
if (!$this->_acl->isAllowed(Zend_Registry::get('role'), $module . ':' . $resource, $action)) {
$request->setModuleName('default')
->setControllerName('index')
->setActionName('login');
} else {
$subdomain = getSubDomainUrl();
$params['username'] = $subdomain;
//echo 'Role='.Zend_Registry::get('role').', Module='.$module . ', Resource=' . $resource. ', Action='. $action;
if ($module == 'default' && $resource == 'index' && ($action == 'index'||$action == 'photography' || $action == 'album' || $action == 'photo-details' || $action == 'wedding-portfolio' || $action == 'wedding-album' || $action == 'wedding-photo-details') && isset($params['username'])&& $params['username'] != 'no') {
$tblUsers = new Application_Model_DbTable_Users();
$usr = $tblUsers->getUserDetailsByName($params['username']);
if ($usr['memb_plan_id'] > 3) {
if ($action == 'wedding-portfolio'||$action == 'index') {
$action = 'wedding-portfolio';
$params = array('sid' => $usr['id']);
}
$request->setModuleName('default')
->setControllerName('index')
->setActionName($action)
->setParams($params);
} else if ($usr['memb_plan_id'] >= 1 && $usr['memb_plan_id'] <= 3) {
if ($action == 'index'||$action=='user-profile') {
$action = 'user-profile';
$params = array('sid' => $usr['id']);
}
$request->setModuleName('default')
->setControllerName('index')
->setActionName($action)
->setParams($params);
} else {
throw new Zend_Controller_Action_Exception('This page does not exist', 404);
}
}
}
} catch (Zend_Acl_Exception $e) {
$request->setModuleName('default')
->setControllerName('index')
->setActionName('login');
}
}