Codeigniter 获取当前的控制器名称和方法名称

在Codeigniter 可以通过下面两个方法获取当前的控制器名称和方法名称

$this->router->fetch_class();
$this->router->fetch_method();

在Codeigniter 3.1.x版本中,可使用

$this->router->class;
$this->router->method;

通过system/core/Router.php 文件源码中 的67到79行 块注释可以看到, $class属性是当前的类名,$method属性是当前的方法名。

参考:

  1. Codeigniter get controller name in helper
  2. How to get Controller, Action, URL informations with CodeIgniter
原文地址:https://www.cnblogs.com/fsong/p/6597257.html