SoFunction
Updated on 2025-03-04

Detailed explanation of how to pass GET parameters in thinkphp

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=1andname=thinkphpThat 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 usenameAttributes 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 passidandnameParameters. You can write HTML code like this:

&lt;form action="//Index/index" method="get"&gt;
    &lt;input type="text" name="id" value="1"&gt;
    &lt;input type="text" name="name" value="thinkphp"&gt;
    &lt;input type="submit" value="submit"&gt;
&lt;/form&gt;

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!