2017-08-01 78 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