PHP代码
<?php /** * 路由器【核心文件】 * @author hxm * @version 1.0 * @since 2015.05.04 */ class Router extends Object { public $module = 'indexAction'; //缺省控制器类名 public $action = 'index'; //控制器缺省方法 public $r = true; //是否可以自定义 /** * 分解路由规则 * * @access public * @return array */ public function path() { if ( trim(_URI_,'/') ) { $url = explode('/', _URI_); $this->module = $url[1]; $this->action = isset($url[2]) && !empty($url[2]) ? $url[2] : $this->action; } else { $this->module = $this->action; } if($this->r == false ) { $made = array( 'module' => $this->module, 'action' => $this->action, ); return $this->getObject($made , 'webApp'); } else { return $this->rewrite($this->module, $this->action); } } /** * 重新定义框架重写规则 * * @access private * @param string $mod 控制器名 * @param string $action 请求的操作 * @param string $route 规则文件 * @return array */ private function rewrite( $mod , $action ) { $file = $this->route(); require $file; $url = '/'.trim( _URI_ ,'/').'/'; if( isset($rules) ) { foreach ($rules as $key => $val) { if(preg_match($val[0], $url) ) { $mod = isset($val[1]['mod']) ? $val[1]['mod'] : $mod; $action = isset($val[1]['action']) ? $val[1]['action'] : $action; } foreach ( $val[2] as $key => $value ) { if ( !(strpos($value, '#') === FALSE) ) { preg_match("$value", $url, $result); $param[$key] = isset($result[1]) ? $result[1] : ''; } else { $param[$key] = $value; } } } } $made = array( 'module' => $mod, 'action' => $action, 'param' => $param ); return $this->getObject($made , 'webApp'); } }
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
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article
Roblox: Grow A Garden - Complete Mutation Guide
3 weeks agoByDDD
Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
How to fix KB5055612 fails to install in Windows 10?
3 weeks agoByDDD
Nordhold: Fusion System, Explained
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
