search
Homephp教程php手册简单的url路由控制[PHP]

简单的url路由控制[PHP]

Jun 06, 2016 pm 07:34 PM
definephpurlcontentcontrolSimpledetailedrouting

无详细内容 无 define('BASE_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);//系统根目录define('MODULE_PATH', BASE_PATH.'modules'.DIRECTORY_SEPARATOR);//模块目录 $module = empty($_GET['m']) ? '' : strtolower($_GET['m']); //文件夹$control = emp

define('BASE_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);//系统根目录
define('MODULE_PATH', BASE_PATH.'modules'.DIRECTORY_SEPARATOR);//模块目录
 
$module = empty($_GET['m']) ? '' : strtolower($_GET['m']); //文件夹
$control = empty($_GET['c'])? 'index' : strtolower($_GET['c']); //文件{类}
$action = empty($_GET['a'])? 'index' : strtolower($_GET['a']); //方法
 
if($module){
     $controlFile = MODULE_PATH . $module . DIRECTORY_SEPARATOR . $control . '.php';
     if( !file_exists($controlFile) )
          echo $module . DIRECTORY_SEPARATOR . $control . '.php'.'类文件不存在'; exit();
 
     include($controlFile);
     $c = new $control;
 
     if( !method_exists($c, $action) )
          echo $c.'方法不存在'; exit();
 
     $c->$action();
}else{
     //默认首页[可用smarty模板引擎加载视图]
     $smarty->display('index.html');
}
/**
写了个简单的路由控制功能,根据参数m,c,a,控制响应url的模块,文件,方法。(MVC)方式URL。
说明:
MVC方式,m模块[对应模块文件夹],c控制器[对应类文件],a方法[对应对象方法]
没有指定module时默认访问系统首页
没有指定control时默认访问index[文件|类],没有该文件时输出文件[类]不存在错误
没有指定action时默认访问index[方法],没有该方法时输出方法不存在错误

例如:http://www.xxx.com/web/index.php?m=admin
访问 module下admin文件夹下的index文件(类名与文件名相同)下的index方法
*/
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.