使用CakePHP的AuthComponent时出现一个奇怪的错误。据我所知,代码本身没有任何问题。它在我的开发机器和生产服务器上运行良好。但是,如果我将app/Core/config.php中的“调试”级别从生产服务器上的2(开发)更改为0(生产),则应用程序将失败,但在错误日志中只有这一项:AuthComponent在开发模式下工作良好,但在生产中不起作用?
PHP Fatal error: Class 'AuthComponent' not found in /path/to/my/app/View/Elements/auth_status.ctp on line 3
我已检查该文件是否存在于lib/Cake/Controller/Component/AuthComponent.php
中。我也试验性地将App::uses('AuthComponent', 'Controller/Component')
添加到AppController和我的个人控制器中,但无济于事。这一个让我难住,我不能在我的开发机器上重现错误。这似乎表明服务器问题,但我无法找到解释,并且文档不清楚运行AuthComponent所需的先决条件。任何想法如何解决它?谢谢!
供参考,这是我的AppController:
class AppController extends Controller {
public $helpers = array('Recaptcha.Recaptcha');
public $components = array(
'Session',
'Auth' => array(
'loginAction' => array(
'controller' => 'users',
'action' => 'login'
),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email')
)
)
)
);
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow();
}
}
为auth_status.ctp代码:
<div class="pull-right">
<?php if (AuthComponent::user('id')): ?>
<?php echo $this->Html->link("Welcome!", '/users/view/'.AuthComponent::user('id'));?>
|
<?php echo $this->Html->link('Logout', '/users/logout');?>
<?php else: ?>
<?php echo $this->Html->link('Login', '/users/login');?>
|
<?php echo $this->Html->link('Register', '/users/register');?>
<?php endif; ?>
</div>
什么是你在你的元素代码? – mark
我用代码编辑了我的问题,欢呼声 – elliot
应用程序在您的appcontroller文件上面使用了声明本身,或者您获得的$ components声明应该就足够了。这很奇怪。它是一个错误页面,你在吗?或正常的200页? – mark