2017-08-01 103 views
0

我具有關於笨控制器和方法3. 基本上,我有一個控制器controller和多個方法(函數) 所以,當我打電話admin/controller我將看到一個index問題法當我選擇admin/controller/doStuff那麼另一種方法是將要推出笨+默認方法時參數存在

但是,我要實現以下目標: admin/controller/1應指向admin/controller/index/1

我試圖解決這一問題:

function _remap($param) { 
    $this->index($param); 
} 

它解決了我的索引部分請求,但它將所有的方法重定向到索引方法.. 任何人有比我更好的主意嗎?

預先感謝您!

回答

1
function _remap($method,$args) 
{ 
    if (method_exists($this, $method)) { 
     /** 
     * Call the method 
     */ 
     $this->$method($args); 
    }else { 
     /** 
     * Otherwise pass $method to index() as an argument 
     */ 
     $this->index($method,$args); 
    } 
}  
+0

我得到的錯誤是:Undefined variable:method。我想$方法應該是從控制器的方法之一,但應該有一個動態的方式..沒有在這裏指定的方法.. – rosuandreimihai

+0

請將$ this - > $方法更改爲$ this - > $ args。它的工作,如果編碼。謝謝! – rosuandreimihai

+0

還有一個問題,如果我使用$ this - > $ args,參數丟失(admin/controller/dostuff/1) – rosuandreimihai