HI i would like to know how to validate a users for a specific controller, so that we can check that a specific users is authenticate before accessing resources of a controller?
问问题
74 次
2 回答
1
你应该看看 Zend_Auth 和 Zend_Acl 组件。
Zend_Auth is responsible for assigning and managing authentication of the user.
Zend_Acl is responsible for managing different permissions and roles for different resources.
这是解释如何实现 Zend_Auth 的教程。
http://akrabat.com/zend-auth-tutorial/
下面的教程解释了 Zend_Auth/Zend_Acl
http://devzone.zend.com/844/zend_acl-zend_auth-example-scenario/
于 2012-07-25T03:40:46.533 回答
0
让我们说对于控制器文件夹中的特定控制器,我们有 CashoutController。在用户访问此控制器之前,我们将使用自定义库对用户进行如下身份验证。
<?php
class CashoutController extends Zc_Controller_Action_User
{
public function init()
{
/* Initialize action controller here */
parent::init();
}
// rest code goes here
}
现在我们定义了新的库名 Zc
<?php
class Zc_Controller_Action_User extends Zc_Controller_Action
{
public function init()
{
parent::init();
$this->validateAccess();
}
private function validateAccess()
{
$auth = Zend_Auth::getInstance();
if (is_null($auth->getIdentity())) {
$this->_helper->redirector('index', 'index');
}
}
}
我们将控制器动作库定义为
<?php
class Birdtoldme_Controller_Action extends Zend_Controller_Action
{
}
希望这对您有所帮助。
于 2012-07-25T03:39:33.547 回答