简体   繁体   English

Yii Rights 不影响用户,为什么?

[英]Yii Rights doesn't affect User, why?

I have set up basic skeleton Yii app, with Rights and User extensions.我已经设置了基本的骨架 Yii 应用程序,带有权限和用户扩展。 Rights works fine, except for User.权限工作正常,用户除外。 I'm using NetBeans 8.0.1.我使用的是 NetBeans 8.0.1。

I have put this code into SiteController and UserController as in the instructions:我已按照说明将此代码放入 SiteController 和 UserController 中:

public function filters() {
    return array(
        'rights',
    );
}

I have noticed a strange thing.我注意到一件奇怪的事情。 Here:这里:

class SiteController extends Controller {

when I was going over the word Controller with the mouse cursor holding CTRL, in a pop-up window NetBeans showed where it was pointing to.当我通过按住 CTRL 的鼠标光标浏览单词Controller ,NetBeans 会在弹出窗口中显示它指向的位置。 It was pointing to the Controller in the application directory.它指向应用程序目录中的控制器。 This is what I expected, and I thought it works because Controller extends RController and so on.这是我所期望的,我认为它有效,因为 Controller 扩展了 RController 等等。

For UserController, it was not working.对于 UserController,它不起作用。

class UserController extends Controller {

Now when I go over the word Controller with the mouse cursor holding CTRL, in a pop-up window NetBeans showes that it is pointing to the Controller not in the application directory but to the Controller in the framework directory.现在,当我在按住 CTRL 的鼠标光标上浏览单词Controller ,NetBeans 在弹出窗口中显示它指向的不是应用程序目录中的控制器,而是框架目录中的控制器。 I thought this is why it's not working.我认为这就是它不起作用的原因。 But since I clicked on it, and jumped to this file, NetBeans shows the same framework Controller for SiteController also, but it still works!但是由于我单击它并跳转到该文件,NetBeans 也为 SiteController 显示了相同的框架控制器,但它仍然有效! So I don't know now if it's only a NetBeans bug or what.所以我现在不知道它是否只是 NetBeans 错误或什么。 But no matter what, what I only care for for is that Rights works for UserController also.但无论如何,我只关心权限也适用于 UserController。

How can I define my UserController to point to the Controller in the application, and not in the framework.如何定义我的 UserController 以指向应用程序中的控制器,而不是框架中的控制器。 But maybe it points to the right place, it's just NetBeans what shows it incorrectly.但也许它指向了正确的地方,只是 NetBeans 错误地显示了它。 But if not this is the problem, than what?但如果不是这就是问题所在,那又是什么?

UPDATE:更新:

I have noticed a thing: somewhere Rights works for User, eg when I see this in the address bar:我注意到一件事:某处权限适用于用户,例如,当我在地址栏中看到此内容时:

project/user/user/view/id/1

it seems to me as it would be user module, then user class, action etc. But when it's not working, I see only:在我看来,它是用户模块,然后是用户类、操作等。但是当它不起作用时,我只看到:

project/user

is it not using class user?不是使用类用户吗? Or what happens here?或者这里会发生什么? What controller is in use?正在使用什么控制器? None?!没有任何?!

I've figured it out (I guess).我已经想通了(我猜)。 In:在:

app/modules/user/controllers

there are more controllers, and I have put有更多的控制器,我已经把

public function filters() {
    return array(
        'rights',
    );
}

only in UserController, that's why it was only working when I called:仅在 UserController 中,这就是为什么它仅在我调用时才起作用:

project/user/user/...

Now there is also DefaultController.现在还有 DefaultController。 That's used, when no other controller is defined in the route.当路由中没有定义其他控制器时使用。 I have put rights filters in DefaultController also, and now it works there also.我也在 DefaultController 中放置了权限过滤器,现在它也可以在那里工作。 So what NetBeans shows as path to Controller is probably only a bug, but I'm not sure, I'm not that professional to decide.所以 NetBeans 显示为 Controller 的路径可能只是一个错误,但我不确定,我不是那么专业的决定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM