我正在尝试调用从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变量?
答案 0 :(得分:1)
$this->controller->{$this->method}();