php - PHP MVC - 使用 URL 格式打开特定选项卡
问题描述
我正在使用 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;
}
}
}
解决方案
仅在#
客户端(浏览器)上用作页面中元素的锚点。此外,它可以在 JavaScript 上下文中使用以处理选项卡等。
它不在服务器端处理,您应该只发送参数:?tab=id
您可以访问tab
服务器端脚本中的参数。
推荐阅读
- json - 用于 json 文档的简单数据 porfiler
- discord.js - 嵌入消息 discord.js
- java - 如何每次创建不同的 BigDecimal 对象?
- swift - UnsafeRawPointer 给出悬空指针警告
- squid - squid--“错误:指令 'hierarchy_stoplist' 已过时。”
- python - Disable_eager_execution with rasa framework not working python
- powershell - 调用 Powershell 脚本 Get-AzureRmSqlServerFirewallRules 时出错?
- spring - 在运行时有条件地覆盖 entityManager 工厂映射
- high-availability - Apache Geode 中的主从功能
- scala - Scala spark 使用逗号作为小数分隔符读取 CSV