Home Backend Development PHP Tutorial thinkphp url中action 没定义 也能访问到模板

thinkphp url中action 没定义 也能访问到模板

Jun 13, 2016 pm 12:16 PM
action method nbsp thinkphp this

thinkphp url中action 没有定义 也能访问到模板?
thinkphp   url中action 没有定义  也能访问到模板?

最近刚刚开始接触thinkphp   的框架,但是在看公司源码的时候,发现url中的action在类中没有对应的实现方法。

thinkphp   中有空操作和空模块之说, 我本来以为是通过空操作来实现的。

最终确认的结果:根本没有经过模块,直接把action对应的模板给display了。

本人刚刚接触thinkphp 不知道为什么  求大神帮忙
------解决思路----------------------
你看下配置里面是不是开启了路由功能,路由功能可以伪造地址;不知道这个是不是你现在遇到的问题。
------解决思路----------------------

引用:
你看下配置里面是不是开启了路由功能,路由功能可以伪造地址;不知道这个是不是你现在遇到的问题。

------解决思路----------------------
在进入用户自定义的action之前,会自动检测是否存在该方法
如果没有就直接读模板,连模板都没有就报一个该方法不存在之类的错误
------解决思路----------------------
引用:
Quote: 引用:

在进入用户自定义的action之前,会自动检测是否存在该方法
如果没有就直接读模板,连模板都没有就报一个该方法不存在之类的错误


谢谢你的解释,你能提供thinkphp官网对此说明的链接给我吗?


这个...没仔细看过官方的,根据它的表现完全可以逆推出原理
如果你感兴趣,可以完整阅读tp的源码
------解决思路----------------------
见 ThinkPHP/Library/Think/Controller.class.php  __call 方法
    /**<br />     * 魔术方法 有不存在的操作的时候执行<br />     * @access public<br />     * @param string $method 方法名<br />     * @param array $args 参数<br />     * @return mixed<br />     */<br />    public function __call($method,$args) {<br />        if( 0 === strcasecmp($method,ACTION_NAME.C('ACTION_SUFFIX'))) {<br />            if(method_exists($this,'_empty')) {<br />                // 如果定义了_empty操作 则调用<br />                $this->_empty($method,$args);<br />            }elseif(file_exists_case($this->view->parseTemplate())){<br />                // 检查是否存在默认模版 如果有直接输出模版<br />                $this->display();<br />            }else{<br />                E(L('_ERROR_ACTION_').':'.ACTION_NAME);<br />            }<br />        }else{<br />            E(__CLASS__.':'.$method.L('_METHOD_NOT_EXIST_'));<br />            return;<br />        }<br />    }<br />
Copy after login
这是一种容错技术,并不需要在使用手册中说明
Statement of this Website
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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

How to turn off private browsing authentication for iPhone in Safari? How to turn off private browsing authentication for iPhone in Safari? Nov 29, 2023 pm 11:21 PM

In iOS 17, Apple introduced several new privacy and security features to its mobile operating system, one of which is the ability to require two-step authentication for private browsing tabs in Safari. Here's how it works and how to turn it off. On an iPhone or iPad running iOS 17 or iPadOS 17, Apple's browser now requires Face ID/Touch ID authentication or a passcode if you have any Private Browsing tab open in Safari and then exit the session or app to access them again. In other words, if someone gets their hands on your iPhone or iPad while it's unlocked, they still won't be able to view your privacy without knowing your passcode

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

Win10/11 digital activation script MAS version 2.2 re-supports digital activation Win10/11 digital activation script MAS version 2.2 re-supports digital activation Oct 16, 2023 am 08:13 AM

The famous activation script MAS2.2 version supports digital activation again. The method originated from @asdcorp and the team. The MAS author calls it HWID2. Download gatherosstate.exe (not original, modified) from https://github.com/massgravel/Microsoft-Activation-Scripts, run it with parameters, and generate GenuineTicket.xml. First take a look at the original method: gatherosstate.exePfn=xxxxxxx;DownlevelGenuineState=1 and then compare with the latest method: gatheros

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

DJI Osmo Action 5 Pro: Release date mooted as retailer reveals launch pricing that could undercut GoPro Hero 13 Black DJI Osmo Action 5 Pro: Release date mooted as retailer reveals launch pricing that could undercut GoPro Hero 13 Black Sep 04, 2024 am 06:51 AM

DJI has not confirmed any plans to introduce a new action camera yet. Instead, it seems that GoPro will get ahead of its rival this year, having teased that it will introduce two new action cameras on September 4. For context, these are expected to a

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

See all articles