【问题标题】:Cakephp 3 giving me Fatal error: Uncaught Error: Class 'Cake\Http\Server' not foundCakephp 3 给我致命错误:未捕获的错误:找不到类'Cake\Http\Server'
【发布时间】:2017-05-21 12:01:30
【问题描述】:

我已经将 cakephp 2 升级到 cakephp 3,这导致了问题,所以我发现我必须用一组新的文件替换 app/webroot,这些文件是 cakephp 3 框架的一部分,但现在我是收到此错误:

Fatal error: Uncaught Error: Class 'Cake\Http\Server' not found in /usr/share/nginx/html/web/app/webroot/index.php:33 Stack trace: #0 /usr/share/nginx/html/web/index.php(47): require() #1 {main} thrown in /usr/share/nginx/html/web/app/webroot/index.php on line 33

经过一番研究,我找到了这个页面:https://api.cakephp.org/3.3/,它显示了应该可用的类,我发现如果我去my_cake_project/web/lib/Cake并运行ls我得到:

basics.php bootstrap.php config Configure Controller Error I18n Log Network src tests Utility View bin Cache Config Console Core Event LICENSE.txt 模型路由测试TestSuite VERSION.txt

但是我遗漏了几个应该在 CakePHP 3 中的库,包括 Http 文件夹,我相信这就是找不到 Cake/Http/Server 的原因。

我已经找到了触发错误的行:

// Bind your application to the server.
$server = new Server(new Application(dirname(__DIR__) . '/config'));

这在 app/webroot/index.php 中。

我尝试将其拆分为:

$a = new Application(dirname(__DIR__) . '/config');
$server = new Server($a);

只是为了测试,我发现它也是说Class Application找不到。

这是我拥有的 app/webroot/index.php 的整个文件:

<?php
/**
 * The Front Controller for handling every request
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @since         0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
// for built-in server
if (php_sapi_name() === 'cli-server') {
    $_SERVER['PHP_SELF'] = '/' . basename(__FILE__);

    $url = parse_url(urldecode($_SERVER['REQUEST_URI']));
    $file = __DIR__ . $url['path'];
    if (strpos($url['path'], '..') === false && strpos($url['path'], '.') !== false && is_file($file)) {
        return false;
    }
}
require dirname(dirname(__DIR__)) . '/vendors/autoload.php';

use App\Application;
use Cake\Http\Server;

// Bind your application to the server.
$server = new Server(new Application(dirname(__DIR__) . '/config'));

// Run the request/response through the application
// and emit the response.
$server->emit($server->run());

所以我也必须缺少 Application 类的文件

基于比较我在lib/Cake 文件夹和https://api.cakephp.org/3.3/ 中的内容,我缺少一堆 cakephp lib 文件夹。

我似乎不仅想念Http,还有:

`Auth`, `Collection`, `Database`, `Datasource`, `Filesystem`, `Form`, `Mailer`, `ORM`, `Shell`, `Utility`, and `Validation`

为什么我缺少这些?以及我在哪里或如何找到所有缺少的库并将其安装到我的 cakephp 应用程序中?

【问题讨论】:

  • updrage 工具只处理了一些升级方面的事情,很多事情还是要手动完成。当然,您也有可能没有正确升级,例如很多人没有意识到升级工具是一个独立的应用程序。不再有lib 文件夹,包括CakePHP 核心在内的依赖项现在通过composer 进行管理,可以在vendors 文件夹中找到。
  • 您最好在CakePHP forumsIRC/Slack 寻求帮助,在那里您可以就这个话题进行更长时间的讨论。

标签: php cakephp php-7 cakephp-3.3 php-7.1


【解决方案1】:

您尚未将所有依赖项下载到供应商文件夹。 我在 Windows 上使用 OpenServer 控制台和 php composer.phar update 对我很有帮助(我之前在我的项目中安装了本地作曲家)。 在我看来,这是因为您在没有管理员权限的情况下安装了框架实例。

【讨论】:

    【解决方案2】:

    我有同样的问题,当我很久以前创建我的项目时,Composer 还处于早期阶段,所以我没有通过它安装 CakePHP。

    要修复它,我必须从示例模板 here 复制 composer.json 文件,然后运行 ​​php composer.phar update。确保选择复制 composer.json 文件的正确分支。

    我在迁移时也使用了这个tool。如果官方升级工具不适合你,你可以使用它。

    【讨论】:

      猜你喜欢
      • 2020-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-14
      • 2023-03-25
      • 2018-09-06
      • 2018-05-11
      • 2020-11-09
      相关资源
      最近更新 更多