3

我已经将 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 应用程序中?

4

2 回答 2

0

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

于 2017-09-08T09:42:23.573 回答
0

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

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

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

于 2020-06-17T18:19:34.590 回答