yii 控制器中的访问控制过滤规则

发布于 2024-09-27 20:30:07 字数 323 浏览 1 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

顾北清歌寒 2024-10-04 20:30:07

您可以挂钩 CWebApplication::beforeControllerAction() 在控制器获取请求之前应用过滤器。

〜thinkt4nk

You can hook into CWebApplication::beforeControllerAction() to apply filters before the controller even gets the request.

~thinkt4nk

忆梦 2024-10-04 20:30:07

您可以使用此功能的一种情况是,如果您在基本控制器中设置一些规则并扩展它。也许您有一些仅限管理员的控制器,那么您可以通过将这些规则添加到所有其他控制器扩展的基本控制器中来节省一些代码?

另外,如果您将行为附加到控制器,则可能会使用它?

我从来没有使用过这个规则,我只是假设。 :)

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. :)

不念旧人 2024-10-04 20:30:07

亲爱的朋友,
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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文