2016.06.29
1. Problem description
Today I used ThinkPHP to create a user login and registration interface. When submitting the form, I don’t know how to fill in the action attribute
Note: I am using ThinkPHP3.2.3 and there may be differences in different versions
2. Solution process
Method 1): localhost/..../index.php/module/controller/method/parameter....
Use the complete URL address to point to where you want to submit. Because I didn't know how to do it at first, I used this clumsiest method. . . .
Method 2): {:U('Module/Controller/Method/Parameter')}
U method is a built-in method of ThinkP to construct a URL. For detailed usage details, please refer to the ThinkPHP Development Manual.
Method 3): __MODULE__/controller/method/parameters,
__CONTROLLER__/method/parameters,
__ACTION__/parameters,
That is, use system constants to simplify addresses, ThinkPHP provides many system constants to save the current URL address,
For example: __ROOT__ Website root directory address
__APP__ Current application (entry file) address
__MODULE__ Current module URL address
__CONTROLLER__ Current controller URL address
__ACTION__ Current operation URL address
__SELF__ Current URL address
3. Summary
General To submit the form, you only need to indicate which php file to submit to and the file address. However, when submitting a form when using ThinkPHP, you must indicate which method of which controller in which module to submit, or a file like index.php that has controllers and methods by default, otherwise an error will occur.
In addition, when searching for solutions online, I found that almost all the answers I found used __RUL__/method/parameters. Then I checked the ThinkPHP3.2.3 manual and found that there is no system constant __URL__. After my own testing, I found that __RUL__ is equivalent to __CONTROLLER__, which is the address of the current controller.
Many of the methods for searching online are from previous versions. I am a newbie and have only used the latest version. I always feel confused when searching online. You should still pay attention to the version when using it. The timeliness of the information is important.
The above introduces 3 the format of form action submission address when using ThinkPHP, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.