我的控制器原生扩展了 app_controller $components 和 $html 帮助程序?

发布于 2024-10-14 22:23:26 字数 1256 浏览 3 评论 0原文

我有我的 UsersController,它当然扩展了我的 app_controller。

在我的 app_controller 中,我的 $components 定义如下:

$components = array('Acl', 'Auth', 'Session', 'RequestHandler');

当我尝试访问用户索引视图时,出现错误(这意味着 Auth 组件尚未在控制器中激活)。

但是

如果我将此行直接放在我的 UsersController 中:

$components = array('Acl', 'Auth', 'Session', 'RequestHandler');

该页面将按预期工作。

我的远程服务器有后一个问题。但我的本地开发环境似乎可以很好地从 app_controller 扩展 $components 。

有谁知道为什么会发生这种情况?

这是我的 app_controller 源代码:

class AppController extends Controller {

var $helpers = array('Html', 'Form', 'Session', 'Ajax', 'Javascript');   
var $components = array('Auth', 'Acl', 'Session', 'RequestHandler'); 

function beforeFilter() {
    //Configure AuthComponent  
    $this->Auth->authorize = 'actions';
    $this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'cms');
    $this->Auth->logoutRedirect = array(Configure::read('Routing.admin') => false, 'controller' =>       'users', 'action' => 'logout');
    $this->Auth->actionPath = 'controllers/';
    $this->Auth->allow('display'); // Allows all action =>  pages for non logged in users.
 }
}

I have my UsersController which of course extends my app_controller.

In my app_controller I have my $components defined as such:

$components = array('Acl', 'Auth', 'Session', 'RequestHandler');

When I try to access my users index view, I get an error (which means that the Auth component has not been activated in the controller).

BUT

If I place this line direct in my UsersController:

$components = array('Acl', 'Auth', 'Session', 'RequestHandler');

The page works as expected.

My remote server has the latter issue. But my local dev environment seems to extend the $components from the app_controller just fine.

Does anyone know why this is happening?

Here is my app_controller source code:

class AppController extends Controller {

var $helpers = array('Html', 'Form', 'Session', 'Ajax', 'Javascript');   
var $components = array('Auth', 'Acl', 'Session', 'RequestHandler'); 

function beforeFilter() {
    //Configure AuthComponent  
    $this->Auth->authorize = 'actions';
    $this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'cms');
    $this->Auth->logoutRedirect = array(Configure::read('Routing.admin') => false, 'controller' =>       'users', 'action' => 'logout');
    $this->Auth->actionPath = 'controllers/';
    $this->Auth->allow('display'); // Allows all action =>  pages for non logged in users.
 }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

維他命╮ 2024-10-21 22:23:26

很久以前我就遇到过这样的问题(但我认为它已经解决了)。 Cake 对“Auth”和“Auth”的顺序很敏感。组件声明中的“Acl”。尝试交换它们。我在您的两个代码示例中看到它们被交换了。

I had a problem like this a way back (but I thought it had been fixed). Cake was sensitive to the order of 'Auth' & 'Acl' in the components declaration. Try swapping them round. I see in your two code samples they are swapped.

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