【发布时间】:2020-06-21 04:43:46
【问题描述】:
我正在使用 PHP MVC,并且我已经编写了以下代码来创建 URL 和加载核心控制器。我的 URL 格式是这样的 - “/controller/method/params”。现在,如果我尝试通过在 URL 中传递选项卡的#id 打开特定的导航选项卡,我会遇到一些问题,它会忽略该部分。我想如果我传递一个选项卡的 ID,那么它应该打开该活动选项卡。任何帮助将不胜感激。
<?php
/*
* App Core Class
* Creates URL & loads core controller
* URL FORMAT - /controller/method/params
*/
class Core
{
protected $currentController = 'Pages';
protected $currentMethod= 'index';
protected $params = [];
public function __construct()
{
//print_r($this->getUrl());
$url = $this->getUrl();
if (empty($url) || !in_array("user_images", $url)){
//Look in controller for first value
if (file_exists('../app/controllers/'. ucwords($url[0]) . '.php' )) {
//if exists, set as controller
$this->currentController = ucwords($url[0]);
//Unset 0 Index
unset($url[0]);
}
require_once '../app/controllers/' . $this->currentController . '.php';
//instantiate controller class
$this->currentController = new $this->currentController;
//check for second part of the url
if (isset($url[1])) {
if (method_exists($this->currentController, $url[1])) {
$this->currentMethod = $url[1];
unset($url[1]);
}
}
//echo $this->currentMethod;
// Get Params
$this->params = $url ? array_values($url) : [];
//call a callback with array of params
call_user_func_array([$this->currentController, $this->currentMethod],
$this->params);
}
}
public function getUrl(){
if (isset($_GET['url'])) {
$url = rtrim($_GET['url'],'/');
$url = filter_var($url, FILTER_SANITIZE_URL);
$url = explode('/',$url);
return $url;
}
}
}
【问题讨论】:
标签: php jquery model-view-controller