Zend_ACL如何获取角色?
阅读 Zend 文档和此处的一些帖子后,我无法弄清楚如何从用户表中获取我的用户角色。
目前我在 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,但如何从用户表中获取角色?该列称为类型,它包含一个指示角色的字符串。
我希望你能帮助我。
问候,
-洛尼
after reading the Zend documentation and some posts here I could not figure out how to get my user role out of a user table.
At the moment I use Zend_Auth like this in an AuthController:
// 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()) {
..
}
And later check it via an Zend_Controller_Plugin and route depending on the result:
if (Zend_Auth::getInstance()->hasIdentity()) {
return;
} elseif ($request->getControllerName() == 'auth' || $request->getControllerName() == 'index') {
return;
} else {
$request->setControllerName('index');
$request->setActionName('index');
return;
}
Now I want to change the route depending on the roll of the user. If the user is an administrator he can reach the AdminController, but how do I get the role out of my user table? The column is called type and it contains a string witch indicates the role.
I hope you can help me.
Greetings,
-lony
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用适配器的 getResultRowObject 方法将您的身份验证结果行存储在 Zend_Auth 中。请参阅 http: //framework.zend.com/manual/en/zend.auth.adapter.dbtable.html#zend.auth.adapter.dbtable.advanced.storing_result_row
Store your auth result row in Zend_Auth using the adapter's
getResultRowObject
method. See http://framework.zend.com/manual/en/zend.auth.adapter.dbtable.html#zend.auth.adapter.dbtable.advanced.storing_result_row谢谢菲尔,它有效!
仅用于完成我的解决方案。我将其添加到 AuthController:
现在我可以通过键入以下内容在任何地方访问我的角色(或用户名):
Thank you Phil, it works!
Only for complition my solution. I added this to the AuthController:
And now I can access my role (or username) everywhere by typing: