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
posted @ 2017-03-21 22:42  五毛钱的饼  阅读(1148)  评论(0编辑  收藏  举报