search
Homephp教程php手册3.2设置默认模块

3.2找不到模块就报错,太不友好了,默认模块失去其作用了。
本来想添加一个Empty模块,想想修改有点多,应该尽量少修改框架源码便于升级,只修改了一行添加了三行:
添加配置"MODULE_LIST" =>array('Home','Admin','等等你想要的模块');
修改\ThinkPHP\Library\Think\Dispatcher.class.php的getModule();    static private function getModule($var) {<br>         $module = (!empty($_GET[$var]) && in_array_case($_GET[$var], C('MODULE_LIST'))) ? $_GET[$var] : C('DEFAULT_MODULE');<br>         if (!empty($_GET[$var]) && !in_array_case($_GET[$var], C('MODULE_LIST'))) {<br>             $_SERVER['PATH_INFO'] = $_GET[$var] . C("URL_PATHINFO_DEPR") . $_SERVER['PATH_INFO'];<br>         }<br>         unset($_GET[$var]);<br> <br>         if ($maps = C('URL_MODULE_MAP')) {<br>             if (isset($maps[strtolower($module)])) {<br>                 // 记录当前别名<br>                 define('MODULE_ALIAS', strtolower($module));<br>                 // 获取实际的模块名<br>                 return ucfirst($maps[MODULE_ALIAS]);<br>             } elseif (array_search(strtolower($module), $maps)) {<br>                 // 禁止访问原始模块<br>                 return '';<br>             }<br>         }<br>         return strip_tags(ucfirst(strtolower($module)));<br>     }在Home模块添加EmptyController处理空模块404吧.

如果直接访问localhost/name,假如不存在name模块会在默认模块下找NameController,再找不到就交给EmptyController处理了。

好像都说明白了,其实不喜欢去改别人框架内的东西,交给别人维护多好。

AD:真正免费,域名+虚机+企业邮箱=0元

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

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.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment