thinkphp6控制器不存在:app\controller\XXX问题解析及解决

转载:http://t.csdn.cn/9vOxU

问题原因在于:

在安装扩展时自动下载更新的vendor/composer/installed.json文件内容和格式与之前的有变化,增加了"packages"节点层次,增加了数组层次。

{
    "packages": [
        {
            "name": "topthink/framework",
            "version": "",
            "version_normalized": "",
            "source": {
                "type": "git",
                "url": "https://github.com/top-think/framework.git",
                "reference": "4b252d78562d4a51a501651f837c26cb9d91624f"
            },
            ......
        }
    ],
    "dev": true,
    "dev-package-names": [
        "symfony/polyfill-php72",
        "symfony/var-dumper",
        "topthink/think-trace"
    ]
}

vendor\topthink\framework\src\think\console\command\ServiceDiscover.php文件在进行获取数据的时候,因为数组层次增加了一个,无法遍历到extra数组中的think元素里面services元素,下面的代码缺少一层遍历:

foreach ($packages as $package) {
    if (!empty($package['extra']['think']['services'])) {
        $services = array_merge($services, (array) $package['extra']['think']['services']);
    }
}

使得自动生成的vendor\services.php文件中的return array为空数组,无法正确加载topthink/think-multi-app,多应用模式失效,就出现了控制器不存在的报错。

修改文件vendor\topthink\framework\src\think\console\command\ServiceDiscover.php文件,增加遍历层次:

foreach ($packages as $package) {
    foreach((array) $package as $subpackage){
        if (!empty($subpackage['extra']['think']['services'])) {
            $services = array_merge($services, (array) $subpackage['extra']['think']['services']);
        }
    }
}

 执行php think service:discover命令,将自动生成vendor\services.php文件即可。

你可能感兴趣的:(PHP,php)