Skip to content

thinkphp8中间件中怎么获取控制器名称和方法名称啊? #3053

Description

@hulang

如下代码结果:
module:user
controller:
action:

controller和action是空的。

<?php

declare(strict_types=1);

namespace app\common\middleware;

use think\facade\Request;

class AuthHandle
{
    public function handle($request, \Closure $next)
    {
        // 应用
        $module = app('http')->getName();
        // 控制器
        $controller = Request::controller();
        // 方法
        $action = Request::action();
        echo ('module:' . $module);
        echo (PHP_EOL);
        echo ('controller:' . $controller);
        echo (PHP_EOL);
        echo ('action:' . $action);
        echo (PHP_EOL);
        //
        return $next($request);
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions