我试图调用从URI site.com/controller/method中提取的控制器和方法
以下是我当前的工作代码:
$__REQUEST__ = new URI_Request($_SERVER["REQUEST_URI"]);
$this->prepareController($__REQUEST__);
if($this->checkClass()) {
$this->controller = new $this->controller();
if($this->checkMethod($__REQUEST__)) {
$method = $__REQUEST__->getMethod();
$this->method = $method;
$this->controller->$method();
}
}但是,我想要这一行
$this->controller->$method(); 以类似的方式工作
$this->controller = new $this->controller();
//achieves something like $this->controller = new IndexController();
//if the URL was something like site.com/index/test (/index/ gets manipulated)例如,类似
$this->controller->$this->method但是,我能理解为什么这不起作用--是否有办法将其链接起来,或者让它从对象特性而不是杂乱变量中引用$method变量?
发布于 2015-03-18 14:38:16
$this->controller->{$this->method}();https://stackoverflow.com/questions/29124597
复制相似问题