action();"; 4. Get it through echo output. Just the method name."/> action();"; 4. Get it through echo output. Just the method name.">
Home > Article > PHP Framework > How to get the currently accessed method name in thinkphp
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.
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:
2, Get the controller name:
echo "The current controller name is:" . request()->controller();
Output result:
3. Get the method name:
echo "The current operation name is:" . request()->action();
Output result:
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!