2012-10-03 26 views
1

在Zend框架中如何限制用戶訪問登錄後頁面的最佳方法
如果用戶沒有登錄,沒有Zend我會寫一個代碼檢查是否在會話中設置了用戶標識,並將該代碼置於通用文件中(用於登錄頁面的所有帖子
)。檢查用戶是否有權訪問Zend框架中的登錄頁面

在Zend框架,我可以檢查,使用Zend_Auth的的hasIdentity方法,但我不
要檢查所有actions.The內的另一個方法,我的想法是創建一個
插件,並勾routeshutdown事件,然後在獲取控制器和動作
從請求對象的名稱我可以決定是否重定向用戶。

請推薦一些好的方法來實現它在Zend框架

回答

2

你通常會寫一個控制器插件並將其添加到前端控制器。通過這種方式,您可以截取所需的調度和路由過程,並將重定向發送到適當的頁面。

class Your_Controller_Plugin_Authcheck extends Zend_Controller_Plugin_Abstract 
{ 
} 

在Bootstrap類:

protected function _initFrontControllerPlugins() 
{ 
    $this->bootstrap(array('AuthcheckPlugin', 'FrontController')); 

    $front = $this->getResource('FrontController'); 
    $front->registerPlugin($this->getResource('AuthcheckPlugin')); 
} 

protected function _initAuthcheckPlugin() 
{ 
    $plugin = new Your_Controller_Plugin_Authcheck(); 

    return $plugin; 
} 

BTW:這是Zend框架1 - 可能工作同2,但我相信你可以改變的事情有點那裏,如果你已經在使用它。

相關問題