Home  >  Article  >  PHP Framework  >  Solve the problem that app\controller\Index does not exist in ThinkPHP6 controller

Solve the problem that app\controller\Index does not exist in ThinkPHP6 controller

藏色散人
藏色散人forward
2021-05-19 14:13:308506browse

The following tutorial column will introduce to you how to solve the problem that the ThinkPHP6 controller does not exist: app\controller\Index. I hope it will be helpful to friends who need it! 1. Check the error first.

Solution 1: Solve the problem that app\controller\Index does not exist in ThinkPHP6 controller

1. Reason for the error: controller Index class was not found, reasons: (1), multiple applications are not configured

(2), the namespace is incorrect

(3), the entry file runs by default The user requested no configuration

(4),

Remarks (multi-application)

: Need to install the multi-application mode extension think-multi-app

Command line: composer require topthink/ think-multi-app2. Solution:

(1). In config/app.php, change 'auto_multi_app' => flase, to true;

(2), check whether the namespace of the controller class is correct

Solve the problem that app\controller\Index does not exist in ThinkPHP6 controller

(3), modify the entry file

<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

// [ 应用入口文件 ]
namespace think;
//定义引用css、js等文件使用的常量 &#39;SITE_URL&#39;
//define(&#39;SITE_URL&#39;,&#39;http://&#39;.$_SERVER[&#39;HTTP_HOST&#39;]);

// 加载composer的psr4命名规范
require __DIR__ . &#39;/../vendor/autoload.php&#39;;

// 执行HTTP应用并响应 创建核心类 获取执行用户所发送请求的http类
$http = (new App())->http;

// 运行用户的请求
//$response = $http->run();
// 运行用户的请求 多应用(设置admin应用)
$response = $http->name(&#39;admin&#39;)->run();
// 响应用户的请求
$response->send();
// 结束
$http->end($response);
Solve the problem that app\controller\Index does not exist in ThinkPHP6 controller

Finally, visit

Solve the problem that app\controller\Index does not exist in ThinkPHP6 controller

in the browser. Solution two: Solve the problem that app\controller\Index does not exist in ThinkPHP6 controller

1. No need to modify the index.php file
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

// [ 应用入口文件 ]
namespace think;

// 加载composer的psr4命名规范
require __DIR__ . &#39;/../vendor/autoload.php&#39;;

// 执行HTTP应用并响应 创建核心类 获取执行用户所发送请求的http类
$http = (new App())->http;

// 运行用户的请求
$response = $http->run();
// 运行用户的请求 多应用(设置admin应用)
//$response = $http->name(&#39;admin&#39;)->run();

// 响应用户的请求
$response->send();

// 结束
$http->end($response);
2. Modify the app.php file

##Solution 3:

Solve the problem that app\controller\Index does not exist in ThinkPHP6 controller

Full path with entry file access (eg): domain name/index.php/application name/controller name/method name

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

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete