Cakephp 3 giving me Fatal error: Uncaught Error: Class 'Cake\Http\Server' not found

你说的曾经没有我的故事 提交于 2020-02-02 11:01:11

问题


I have done a cakephp 2 to cakephp 3 upgrade, and that was causing problems, so I found I had to replace the app/webroot with a new set of files that were part of the cakephp 3 skeleton, but now I am getting this error:

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

After some research, I found this page: https://api.cakephp.org/3.3/, which shows the classes that should be availabe, and I found that if I go to my_cake_project/web/lib/Cake and run ls I get:

basics.php bootstrap.php config Configure Controller Error I18n Log Network src tests Utility View bin Cache Config Console Core Event LICENSE.txt Model Routing Test TestSuite VERSION.txt

But I am missing several libraries that are supposed to be in CakePHP 3, including the Http folder, and I believe that is why Cake/Http/Server is not found.

I have tracked down the line that is triggering the error to this:

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

This is in app/webroot/index.php.

I tried splitting that up to:

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

just for testing, and I found that it is also saying that the Class Application can not be found.

This is the whole file of app/webroot/index.php that I have:

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

So I must be missing the file for the Application class too

And based on comparing what I have in lib/Cake folder with https://api.cakephp.org/3.3/ I a missing a bunch of cakephp lib folders.

I seem to be missing not just Http, but also:

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

Why am I missing these?, and where or how can I find and install all the missing libraries into my cakephp appliation?


回答1:


You haven't downloaded all dependencies to vendor folder. I used OpenServer console on Windows and php composer.phar update was helpful for me (I had installed composer locally to my project before). In my opinion, that happened because you had installed the framework instance without Administrator rights.



来源:https://stackoverflow.com/questions/41510526/cakephp-3-giving-me-fatal-error-uncaught-error-class-cake-http-server-not-fo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!