text
In ThinkPHP, we can use URL addresses to pass parameters. The ThinkPHP framework automatically parses parameters in the URL address and passes them to the corresponding controller and method.
For example, our URL address is:http://localhost//Index/index?id=1&name=thinkphp
,inid=1
andname=thinkphp
That is the passed parameter. In the controller, we can use$this->request->param()
Method to get the parameters passed in the URL address. For example:
<code><code>public function index() { $id = $this->request->param('id'); $name = $this->request->param('name'); echo 'ID=' . $id . ', Name=' . $name; }</code></code>
In this way, when we access the above URL address, the controller outputs:ID=1, Name=thinkphp
。
In addition to passing parameters at URL addresses, we can also use forms to pass parameters. In HTML forms, we can usename
Attributes to identify the parameters that need to be passed, and can also be used in the controller.$this->request->param()
Method to get the parameters passed in the form.
For example, in an HTML form, we need to passid
andname
Parameters. You can write HTML code like this:
<form action="//Index/index" method="get"> <input type="text" name="id" value="1"> <input type="text" name="name" value="thinkphp"> <input type="submit" value="submit"> </form>
In the controller, we can also use$this->request->param()
Method to get the parameters passed in the form. For example:
<code><code>public function index() { $id = $this->request->param('id'); $name = $this->request->param('name'); echo 'ID=' . $id . ', Name=' . $name; }</code></code>
In this way, when we submit the form, the controller will also output:ID=1, Name=thinkphp
。
The above is the detailed content of how thinkphp passes GET parameters. For more information about thinkphp passes GET parameters, please pay attention to my other related articles!