我的控制器原生扩展了 app_controller $components 和 $html 帮助程序?
我有我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很久以前我就遇到过这样的问题(但我认为它已经解决了)。 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.