【发布时间】:2020-08-31 01:46:29
【问题描述】:
我使用 Mamp 创建 PHP 服务器。 默认主页是 homecontroller。但是当我点击指向主页或任何 url 的 url 时,出现问题:在此服务器上找不到请求的 URL /ltw/home。当我替换受保护的 $controller = "home";通过任何控制器,它可以在我进入索引页面时加载。
class App
{
protected $controller = "home";
protected $action = "default";
protected $params = [];
public function __construct()
{
//Array ( [0] => home [1] => 1 [2] => 2 [3] => 3 )
$arr = $this->UrlProcess();
// print_r($arr);
//Handle Controller
if (file_exists("./mvc/controllers/". $arr[0] ."Controller.php")){
$this->controller = $arr[0];
unset($arr[0]);
}
require_once "./mvc/controllers/" . $this->controller . "Controller.php";
$this->controller = new $this->controller;
//Handle Action
if (isset($arr[1]) && method_exists($this->controller, $arr[1])){
$this->action = $arr[1];
unset($arr[1]);
}
//Handle Params
$this->params = $arr?array_values($arr):[];
$arr2 = array($this->params);
//Call a controller->action->params
call_user_func_array([ $this->controller, $this->action ], $arr2 );
// print_r($this->params);
}
这个错误只发生在mac和xampp上,
【问题讨论】: