2015-10-06 50 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 
     }