Zend_ACL如何获得角色?
问题描述:
在阅读Zend文档和一些帖子后,我无法弄清楚如何让我的用户角色脱离用户表。Zend_ACL如何获得角色?
此刻,我在AuthController使用Zend_Auth的是这样的:
// Set authentication adapter and map ID and Cre.
// only admins could log in here
$adapter = new Zend_Auth_Adapter_DbTable($this->db,
'customers',
'login',
'password',
'MD5(?)');
$adapter->setIdentity($form->getValue('username'))
->setCredential($form->getValue('password'));
// Check if authentification is right
$result = Zend_Auth::getInstance()->authenticate($adapter);
if (!$result->isValid()) {
..
}
后来通过根据结果的Zend_Controller_Plugin和路由检查:
if (Zend_Auth::getInstance()->hasIdentity()) {
return;
} elseif ($request->getControllerName() == 'auth' || $request->getControllerName() == 'index') {
return;
} else {
$request->setControllerName('index');
$request->setActionName('index');
return;
}
现在我想改变路线取决于用户的滚动。如果用户是管理员,他可以访问AdminController,但是如何从我的用户表中获取角色?该列称为类型,它包含一个字符串女巫表示角色。
我希望你能帮助我。
问候,
-lony
答
商店使用适配器的getResultRowObject
方法的权威性结果行Zend_Auth的。见http://framework.zend.com/manual/en/zend.auth.adapter.dbtable.html#zend.auth.adapter.dbtable.advanced.storing_result_row
答
谢谢菲尔,它的工作原理!
只适用于我的解决方案。我已将此添加到AuthController:
// fetches role and login name out of
// user table and store it in auth session
$data = $adapter->getResultRowObject(array(
'role',
'username'
));
Zend_Auth::getInstance()->getStorage()->write($data);
现在我可以访问我的角色(或用户名)到处键入:
$role = Zend_Auth::getInstance()->getIdentity()->role;