Home > PHP Framework > ThinkPHP > Solve the problem that ThinkPHP6 prompts that the controller does not exist

Solve the problem that ThinkPHP6 prompts that the controller does not exist

藏色散人
Release: 2021-01-07 09:10:45
forward
10061 people have browsed it

The following tutorial column of thinkphp will introduce to you the solution to the problem that ThinkPHP6 prompts that the controller does not exist. I hope it will be helpful to friends in need!

Solve the problem that ThinkPHP6 prompts that the controller does not exist

ThinkPHP 6 prompts that the control controller does not exist


thinkphp 6 defaults to single application mode, when multiple applications are required , you need to install the multi-application mode extension think-multi-app.

composer require topthink/think-multi-app
Copy after login

Then delete the app\controller directory that comes with the framework and create the application directory you need.

For example: \app\index\controller\Index.php

<?php
namespace app\index\controller;use app\BaseController;class Index extends BaseController
{    public function index()
    {        return 'hello index';
    }
}
Copy after login

Access this method: http://www.study_tp6.com/public/index.php/index/index/index

Result prompt: The controller does not exist app\controller \index


Find the reason:

1. The think-multi-app extension was installed according to the official documentation, and it was prompted that the installation was successful.

2. The namespace of the controller is not written correctly.

3. The access path is the same as the directory name, controller, and method name, and the access address is correct.

4. It is said on the Internet that in the configuration file config/app.php, change 'auto_multi_app' => flase, to true,

But the version I am using is ThinkPHP 6.0. 4. There is no such parameter in the configuration file. I tried adding it but it didn’t work.

5. Is there something wrong with the downloaded framework? I redownloaded the framework and reinstalled the multi-application extension, but it still didn't work.


Solution:

Thanks [ikgade] for sharing in the official comments, gave it a try, and solved this pitfall.

This is the author's idea and plan:

为什么提示 “控制器不存在:app\controller\Admin”?
因为安装多应用模式扩展执行的指令没有生效 php think service:discover 自动注册扩展包的系统服务。
为什么自动注册拓展包服务失败,详见代码:
vendor/topthink/framework/src/think/console/command/ServiceDiscover.php
第34行代码$package['extra']['think']['services']为空,导致生成自动注册服务文件
services.php 中没有注册的代码。
天坑!
怎么解决呢?
首先找到你加入的拓展,在这里:
vendor/composer/installed.json
然后把所有的$package['extra']['think']['services']复制粘贴到services中,或者修改以下文件的代码:
vendor/topthink/framework/src/think/console/command/ServiceDiscover.php
Copy after login

Copy the services value in vendor/composer/installed.json to the array of vendor/services.

The above is the detailed content of Solve the problem that ThinkPHP6 prompts that the controller does not exist. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template