Home > PHP Framework > ThinkPHP > body text

How to get the currently accessed method name in thinkphp

藏色散人
Release: 2022-12-08 09:49:58
Original
2037 people have browsed it

thinkphp gets the method name currently being accessed: 1. Open the corresponding tp file; 2. Determine the address to be accessed; 3. Get the method name through "request()->action();"; 4. Just output the method name obtained through echo output.

How to get the currently accessed method name in thinkphp

The operating environment of this tutorial: Windows 7 system, ThinkPHP version 5, Dell G3 computer.

How does thinkphp get the name of the currently accessed method?

thinkphp5 gets the current module, controller and method name

Problem analysis:

thinkphp5 series needs to get the current module, control For the device and method names, you can use the built-in Request class or the request helper function. Next, give an example:

Assume that the address we are visiting now is index/member/add, let’s get the module, controller, and method name of this address

1. Get the module name:

echo "The current module name is:" . request()->module();

Output result:

How to get the currently accessed method name in thinkphp

2, Get the controller name:

echo "The current controller name is:" . request()->controller();

Output result:

How to get the currently accessed method name in thinkphp

3. Get the method name:

echo "The current operation name is:" . request()->action();

Output result:

How to get the currently accessed method name in thinkphp

Recommended study: "thinkPHP Video Tutorial"

The above is the detailed content of How to get the currently accessed method name in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!