CakePHP致命错误:找不到类别“ErrorHandler”

des4xlb0  于 2022-11-12  发布在  PHP
关注(0)|答案(3)|浏览(181)

我已经通过“cake bake testsuit”生成了测试套件,并在我的应用程序中使用了localhost/test.php。因此,当我尝试运行其中一个测试时,出现了错误(否则测试有效):``

Fatal error: Class 'ErrorHandler' not found in Z:\home\prodvigator\www\cake\libs\object.php on line 201

这个模型和控制器是由scaffold生成的,我不认为这个源代码中有错误。
使用:CakePHP 1.3最新的简单测试

vc9ivgsu

vc9ivgsu1#

在我的情况下,删除文件夹/app/tmp/cache/persistent中的所有文件解决了问题。

vshtjzan

vshtjzan2#

请尝试检查生成的测试中是否有写在文件顶部的错误。
有时候我在模型和控制器测试中都发现了类似的东西。

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
eit6fx6z

eit6fx6z3#

在我的例子中,错误是:

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();
        }
    }
?>

相关问题