search
Homephp教程php手册ThinkPHP空模块和空操作详解

这篇文章主要介绍了ThinkPHP空模块和空操作,需要的朋友可以参考下

ThinkPHP的空模块和空操作也是很有实用意义的功能,空模块的概念就是当ThinkPHP找不到指定模块的时候,它会尝试去定位空模块(EmptyAction),执行空模块里面的index操作。同理,空操作也是同样的概念,,当系统找不到指定模块下的操作方法的时候,就会尝试去定位空操作方法(empty)。其实很好理解,就有点类似php虚拟主机里面的自定义404页面,但它比自定义404更加灵活,利用这个机制,我们可以实现错误页面和一些URL的优化,下面分别详细介绍下空模块和空操作的写法。

1.空模块,在项目中定义EmptyAction类:

这就是一个简单的空模块类,当然您也可以在里面做一些更加复杂的操作,一切都得根据项目的需求来写,这里只是做了演示。

2.空操作,空操作即在指定的模块下面定义,比如说,我们在User这个模块,也就是UserAction类下面定义一个空操作。

display(); } public function demo(){$this->display(); } public function _empty(){ //该方法即为空操作 echo '当前操作不存在'; } } ?>

代码很简单,这就是一个空方法,并且空模块和空操作还可以同时使用,用以完成更加复杂的操作。

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

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

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 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

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.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor