【问题标题】:CakePHP fatal error: Class 'ErrorHandler' not foundCakePHP 致命错误:找不到类“ErrorHandler”
【发布时间】:2010-11-30 11:46:59
【问题描述】:
我已经通过“cake bake testsuit”生成了testsuits,并为我的应用程序使用了localhost/test.php。
因此,当我尝试运行其中一项测试时出现错误(其他测试有效):
Fatal error: Class 'ErrorHandler' not found in Z:\home\prodvigator\www\cake\libs\object.php on line 201
这个模型和控制器是由脚手架生成的,我认为这个来源没有错误。
使用:
CakePHP 1.3
最新的 SimpleTest
【问题讨论】:
标签:
unit-testing
cakephp
error-handling
【解决方案1】:
就我而言,删除文件夹/app/tmp/cache/persistent 中的所有文件解决了问题。
【解决方案2】:
尝试检查生成的测试是否存在写入文件顶部的错误。
有时我会在模型和控制器测试中找到类似的东西。
Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead in /projectname/cake/console/templates/default/classes/test.ctp on line 22
【解决方案3】:
就我而言,错误是:
Fatal error: Uncaught Error: Class 'ErrorHandler' not found in C:\[path]\core\cake\libs\object.php on line 211
( ! ) Error: Class 'ErrorHandler' not found in C:\[path]\core\cake\libs\object.php on line 211
我在尝试访问 http://localhost/user_accounts/index 时发生错误
我已经在 app\views\user_accounts\index.ctp 创建了具有以下内容的视图:
<div>
Text from div
</div>
我也在 app\controllers\user_accounts_controller.php 中创建了相应的控制器:
<?php
class UserAccountsController extends AppController {
public function index() {
// Render the view in /views/user_accounts/index.ctp
$this->render();
}
}
?>
由于我没有将模型与此控制器相关联,因此我错过了这个:var $uses = array();。如果错误更明确,例如“您没有与此控制器关联的模型”之类的错误,那会节省我的时间。
解决方法是:
<?php
class UserAccountsController extends AppController {
// Use this controller without a need for a corresponding Model file.
var $uses = array();
public function index() {
// Render the view in /views/user_accounts/index.ctp
$this->render();
}
}
?>