繁体   English   中英

找不到Composer PSR-4类

[英]Composer PSR-4 class not found

我有以下目录结构 在此处输入图片说明

这是我在composer.json文件中使用psr-4的方法

"autoload": {
    "psr-4": {"MyMVC\\": "app/"}
},

现在在我的初始化文件中,我试图像

<?php namespace MyMVC;

use MyMVC\Core\Config;
use MyMVC\Controllers;

class Application
{
    /**
     * Takes the arguments and execute the requested route
     *
     * @param  [type] $controller name of the controller
     * @param  [type] $method     name of method
     * @param  array  $arguments  an array of arguments to be passed into method
     * @access private
     */
    private function dispatch($controller, $method, array $arguments)
    {
        $controller = 'Controllers\\' . ucfirst($controller) . 'Controller';
        $controllerObject = new $controller;
    }

我的HomeController看起来像这样

<?php namespace MyMVC\Controllers;

class HomeController
{

    function __construct()
    {
        echo 'Hello World';
    }
}

现在,如果我进入url`http:// localhost / mymvc / home / bla / bla ', 则会收到错误消息

Fatal error: Class 'Controllers\HomeController' not found in /var/www/html/mymvc/app/init.php on line 136

在申请中应

$controller = 'MyMVC\\Controllers\\' . ucfirst($controller) . 'Controller';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM