Heim  >  Artikel  >  PHP-Framework  >  Informationen zu den aktuellen Controller- und Methodennamen können im TP6-Mehrfachanwendungsmodus nicht abgerufen werden

Informationen zu den aktuellen Controller- und Methodennamen können im TP6-Mehrfachanwendungsmodus nicht abgerufen werden

藏色散人
藏色散人nach vorne
2020-07-04 13:37:115634Durchsuche

下面由thinkphp框架教程栏目给大家介绍关于TP6多应用模式下获取不到当前控制器和方法名的问题,希望对需要的朋友有所帮助!

前言:最近使用TP6做了一套项目,发现多应用模式下使用 $this->request->controller()$this->request->action() 无法获取到当前的控制器和方法名,自己研究了一下,找了个笨办法,记录一下,如果大家有更好的办法,欢迎留言。

开发环境

windwos 10
PHP 7.3
TP 6.0.2

问题重现

1、先创建一个新项目

composer create-project topthink/think tp60
cd tp60/
composer require topthink/think-multi-app

2、修改 /config/app.php 加入下面两行

//开启应用快速访问
'app_express'      => true,

3、修改 /config/route.php

// 是否强制使用路由
'url_route_must' => true,
// 路由是否完全匹配
'route_complete_match' => true,

4、删除 /app 下面的 controller 目录,创建 index 文件夹,目录结构如下:

Informationen zu den aktuellen Controller- und Methodennamen können im TP6-Mehrfachanwendungsmodus nicht abgerufen werden

5、上代码,IndexController.php 的内容:

<?php namespace app\index\controller;

use app\BaseController;

class IndexController extends BaseController
{
    public function index()
    {
        dd($this->request->controller(), $this->request->action());
    }
}

/app/index/route/app.php 的内容

<?php

use think\facade\Route;

Route::group(function () {
    Route::get(&#39;/&#39;, &#39;IndexController@index&#39;);
})->prefix(&#39;\app\index\controller\\&#39;);

6、启动然后访问该应用,控制器与方法输出都是空。

php think run

Informationen zu den aktuellen Controller- und Methodennamen können im TP6-Mehrfachanwendungsmodus nicht abgerufen werden

解决方案

调试发现 $this->request 对象的 rule 里面有当前控制器和方法名

Informationen zu den aktuellen Controller- und Methodennamen können im TP6-Mehrfachanwendungsmodus nicht abgerufen werden

可使用 $this->request->rule()->getName()$this->request->rule()->getRoute() 获取,

Informationen zu den aktuellen Controller- und Methodennamen können im TP6-Mehrfachanwendungsmodus nicht abgerufen werden

谜之操作

另外调试发现,Controllerinit 方法好像没执行,在 Request 里面打两个断点,一样可以访问,可以用上面的方法获取到控制器和方法名。
Informationen zu den aktuellen Controller- und Methodennamen können im TP6-Mehrfachanwendungsmodus nicht abgerufen werden

Informationen zu den aktuellen Controller- und Methodennamen können im TP6-Mehrfachanwendungsmodus nicht abgerufen werden


Das obige ist der detaillierte Inhalt vonInformationen zu den aktuellen Controller- und Methodennamen können im TP6-Mehrfachanwendungsmodus nicht abgerufen werden. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Dieser Artikel ist reproduziert unter:learnku.com. Bei Verstößen wenden Sie sich bitte an admin@php.cn löschen