Codeigniter 4 Current/Active 控制器

Codeigniter 4 Current/Active Controller

在 Codeigniter 3 中,可以使用以下代码获得当前活动 class 和方法:

    $active_controller = $this->router->fetch_class();
    $active_function = $this->router->fetch_method();

Codeigniter 4 中有这样的功能吗?

值得一提的是,那些 类 从未正式成为 CI3 (https://codeigniter.com/user_guide/installation/upgrade_300.html?highlight=fetch_class). Bearing in mind CI4 is a lot more flexible and that routes are defined more variably I would look at the routing side of things and extract it from there (https://codeigniter4.github.io/userguide/incoming/incomingrequest.html#the-request-url) 的一部分。

在 CodeIgniter 4 中

$router = service('router'); 
$controller  = $router->controllerName();  

$router = service('router');
$method = $router->methodName();