我有问题,我不知道如何解决这个问题。
此行代码的问题:
public function ExecuteAction() {
return $this->{$this->action}();
}
所有其他工作正常控制器成功加载,但我对此有致命错误。
致命错误:方法名称必须是第 27 行 D:\xampp\htdocs\Workplace\MVC\lib\BaseController.php 中的字符串
检查我的代码:
索引.php
$fController = new FController($_GET);
$controller = $fController->CreateController();
$controller->ExecuteAction();
控制器
public function createController()
{
if(class_exists($this->controller)) {
$parent = class_parents($this->controller);
if(in_array('BaseController', $parent)) {
if(method_exists($this->controller, $this->action)) {
return new $this->controller($this->action, $this->url);
}else {
echo "Method no exists";
}
}else {
echo "Bad Controller";
}
} else {
echo "Controller ". $this->controller . " class no exists";
}
}
基本控制器
abstract class BaseController {
protected $urlvalues;
protected $action;
/*
* Construct
*
* @param string $action
* @param array $url
*
*/
public function __construct($action, $urlvalues) {
$this->action = $action;
$this->urlvalues = $urlvalues;
}
/*
* Execute acction
*
*/
public function ExecuteAction() {
return $this->{$this->action}();
}
localhost/Workplace/MVC/index.php?controller=hello&action=say&id=5