php 自制简单路由类 望大神指点

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 自制简单路由类 望大神指点相关的知识,希望对你有一定的参考价值。

class route
{
/** @var null 模块 */
private static $module = null;
/** @var null 控制器 */
private static $controller = null;
/** @var null 方法 */
private static $action = null;
/** @var 控制器url */
private static $controllerPath;

/**
* route constructor.
* @param array $config url
*/
public function __construct($config = [])
{
$var_parse = explode(‘/‘, $config[‘r‘]);
if (count($var_parse) == 3){
self::$module = $var_parse[0];
self::$controller = ucwords($var_parse[1]).‘Controller‘;
self::$action = $var_parse[2];
self::$controllerPath = APP_ROOT.‘/controllers/‘.self::$module.‘/‘.self::$controller.‘.php‘;
}elseif(count($var_parse) == 2){
self::$controller = ucwords($var_parse[0]).‘Controller‘;
self::$action = $var_parse[1];
self::$controllerPath = APP_ROOT.‘/controllers/‘.self::$controller.‘.php‘;
}
}

/**
* 执行控制器方法
* @return null
*/
public static function run(){
self::register();
$controller = new self::$controller;
if(method_exists($controller, self::$action)){
$action = self::$action;
$controller->$action();
}else{
header("HTTP/1.1 404 Not Found");
}
}

/**
* 加载类
*/
public static function register(){
spl_autoload_register("self::loadClass");
}

//自动加载
public static function loadClass(){
if(!file_exists(self::$controllerPath)){
header("HTTP/1.1 404 Not Found");
}
require_once self::$controllerPath;
}
}



























































以上是关于php 自制简单路由类 望大神指点的主要内容,如果未能解决你的问题,请参考以下文章

php递归的问题,请大神门指点

登陆界面出现用户名:ASPNET,不知道密码也无法使用administrator用户名登陆,望大神求救!!!!

求大神指点 ---- ASA配置ACL规则

自己封装了一个EF的上下文类.,分享一下,顺便求大神指点

Javaweb题目,求大神解答指点

dvwa试验中php allow_url_include=on 怎么打开?跪求大神指点!