在Codeigniter

时间:2018-01-22 10:34:47

标签: codeigniter

对于我的Codeigniter(v 3.1.7)项目,我创建调试菜单(如prestashop),其中包含登录用户的所有信息,页面错误...以快速调试页面。

所以,我想调用控制器的名称和函数的名称。 如果我在页面“登录”,我想显示:

Controller: Account
Function: Login

我在this post上找到了我的问题提示,但我们使用了网址重写,网址的名称并不是控制器的真实名称。

2 个答案:

答案 0 :(得分:3)

如果CI版本低于3,则必须使用:

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

如果你的CI版本是3或以上。不推荐使用这些方法。

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

您可以改为访问属性。

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

请参阅codeigniter user guide

URI路由方法fetch_directory(),fetch_class(),fetch_method() 使用属性CI_Router :: $ directory,CI_Router :: $ class和CI_Router :: $方法是公共的,并且它们各自的fetch _ *()不再执行任何其他操作来返回属性 - 保留它们没有意义。 / p>

这些都是内部的,未记录的方法,但我们现在选择弃用它们以保持向后兼容性以防万一。如果你们中的一些人已经使用过它们,那么你现在可以只访问这些属性:

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

答案 1 :(得分:2)

您可以使用URI类来获取该信息:

$this->uri->segment(n); // n=1 for controller, n=2 for method, etc