CakePHP 3:未找到 Class 'Cake\Routing\DispatcherFactory'

CakePHP 3 : Class 'Cake\Routing\DispatcherFactory' not found

我在 CakePHP 3 开发了一个应用程序。它在我的 localhost 服务器上运行良好,但是当我将它上传到共享主机时,它开始提供 500 Internal server error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at admin@main-hosting.eu to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

我尝试了 google 上的所有解决方案,但没有任何帮助。 然后我找到 php 错误日志并在其中找到这些行。

[19-Jun-2016 18:29:08 UTC] PHP Fatal error:  Uncaught Error: Class 'Cake\Routing\DispatcherFactory' not found in /home/username/public_html/webroot/index.php:33
Stack trace:
#0 {main}
  thrown in /home/username/public_html/webroot/index.php on line 33

/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(__DIR__) . '/config/bootstrap.php';

use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Routing\DispatcherFactory;

$dispatcher = DispatcherFactory::create();    // Line 33
$dispatcher->dispatch(
    Request::createFromGlobals(),
    new Response()
);

这里有什么问题吗?

如果您使用的是共享主机,请检查文件和文件夹权限:

  1. 你的cake项目中的所有文件都必须有644权限

644 means that files are readable and writeable by the owner of the file and readable by users in the group owner of that file and readable by everyone else.

  1. 您的蛋糕项目中的所有文件夹必须具有 755 权限

755 is the same thing, it just has the execute bit set for everyone. The execute bit is needed to be able to change into the directory. This is why directories are commonly set to 755.

  1. 检查 运行 您的 Cake 项目的所有扩展和配置,并检查重写模块是否正常工作。

希望这对你有用...