yii 控制器中的访问控制过滤规则
在 yii 控制器中编写访问控制规则时,可能需要设置的参数 对于规则来说,有 'action' - 设置规则适用的操作; '用户','角色'等。
现在,yii 指南(pdf)和参考(我有 chm 文件)都说可以设置, 另外,规则应应用到的控制器的控制器 ID。
现在,如果我们已经将这些规则放入控制器类/文件中,我们如何能够 将其他控制器(当前控制器除外)作为参数放在这里,意思是 我们在这里提到的 id 的其他控制器会如何 - 它如何知道有适用于它的规则,因为它是在完全其他控制器类/文件中编写的?
如果控制器是写在控制器之外的,控制器如何知道提到它的规则, 在完全不同的控制器中?
When writing rules for access control in yii controllers, possible parameters to be set
for a rule are 'action' - sets to which action the rule applies; 'users', 'roles', etc.
Now, both the yii guide (pdf) and reference (I have chm file) say that it's possible to set,
also, a controller id for the controller the rule should apply to.
Now, if we are already putting these rules in a controller class/file, how would we be able
to put some other controller (other than the current one) as the parameter here, meaning
how would some other controller whose id we mention here - how would it know there is a rule that applies to it, since it's written in a completely other controller class/file?
How would the controller be aware of a rule that mentions it, if it's written outside of it,
in a completely different controller?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以挂钩 CWebApplication::beforeControllerAction() 在控制器获取请求之前应用过滤器。
〜thinkt4nk
You can hook into CWebApplication::beforeControllerAction() to apply filters before the controller even gets the request.
~thinkt4nk
您可以使用此功能的一种情况是,如果您在基本控制器中设置一些规则并扩展它。也许您有一些仅限管理员的控制器,那么您可以通过将这些规则添加到所有其他控制器扩展的基本控制器中来节省一些代码?
另外,如果您将行为附加到控制器,则可能会使用它?
我从来没有使用过这个规则,我只是假设。 :)
One case where you could use this is if you set some rules in a base controller and extend it. Maybe you have some admin-only controllers, then you can save a little code by just adding these rules into a base Controller that all other controllers extend?
Also, this might be used if you are attaching Behaviors to the controller?
I've never used this rule though, I'm just hypothesizing. :)
亲爱的朋友,
Yii 为我们提供了 3 种类型的用户组
(*)- 全体(客人),
(@)- 已注册,
(管理员)- 对于超级用户,我们可以从控制器/公共函数 accessRules() 使用它
,如果您想要自定义用户权限,您也可以使用
1)ttp://www.yiiframework.com/extension/yii-user-management/
你还可以使用最适合定制的“Yii-Rights”
2)http://www.yiiframework.com/forum/index.php?/topic/10556-extension-rights/page_p_51869#entry51869
尊敬,
巴维克·乔汉
Dear Friend,
Yii give us 3 type of user groups
(*)- for All(guest),
(@)- for registered,
(admin)- for super user we can use it from Controller / public function accessRules()
add if you wanna custom user rights than u can also use
1)ttp://www.yiiframework.com/extension/yii-user-management/
and u can also use "Yii-Rights" which is best for customization
2)http://www.yiiframework.com/forum/index.php?/topic/10556-extension-rights/page_p_51869#entry51869
Regard,
Bhavik Chauhan