2015-10-06 51 views
1

我想在“后的控制器构造”挂钩,以获得所谓的控制器的名称:笨在后的控制器构造钩子获取当前控制器

<?php 
function authenticate() { 
    $CI =& get_instance(); 
    $controller = $CI->router->class; 
} 

但我收到此错误信息:

一个PHP错误遇到

严重性:注意

消息:试图让非OB的财产JECT

文件名:钩/ post_controller_constructor.php

行号:5

回溯:

文件:/ ... /CodeIgniter-3.0rc3/application/hooks/post_controller_constructor.php 行:5 功能:_error_handler

文件:/ ...的index.php 线:292 功能:require_once

任何想法为什么?

回答

0

我不确定这一点。但你可以尝试这样。 fetch_class用于获取类名,方法用于获取方法名。

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

我已经尝试过,尽管它是不赞成的方法。不过谢谢你的建议。 –

+0

您需要做什么?没有其他办法。 –

+0

我需要它来检查用户是否在运行不在例外列表中的方法之前登录。是的,我找到了另一种方式! =) –

0
<?php 
     function authenticate() 
     { 
     $CI = &get_instance(); 
     $controller = $CI->router->fetch_class(); //Controller name 
     $method  = $CI->router->fetch_method(); //Method name 
     }