search
HomePHP FrameworkThinkPHPHow thinkphp passes GET parameters

In ThinkPHP, we can use URL addresses to pass parameters. The ThinkPHP framework will automatically parse the parameters in the URL address and pass them to the corresponding controllers and methods.

For example, our URL address is: http://localhost/index.php/Index/index?id=1&name=thinkphp, where id=1 and name=thinkphp are the parameters passed. In the controller, we can use the $this->request->param() method to get the parameters passed in the URL address. For example:

<code><pre class='brush:php;toolbar:false;'>public function index() { $id = $this-&gt;request-&gt;param(&amp;#39;id&amp;#39;); $name = $this-&gt;request-&gt;param(&amp;#39;name&amp;#39;); echo &amp;#39;ID=&amp;#39; . $id . &amp;#39;, Name=&amp;#39; . $name; }</pre>

In this way, when we access the above URL address, the controller will output: ID=1, Name=thinkphp.

In addition to passing parameters through URL addresses, we can also use forms to pass parameters. In the HTML form, we can use the name attribute to identify the parameters that need to be passed, and in the controller, we can also use the $this->request->param() method to get the parameters passed in the form.

For example, in an HTML form, we need to pass the id and name parameters. Then you can write HTML code like this:

<form action="/index.php/Index/index" method="get">
    <input type="text" name="id" value="1">
    <input type="text" name="name" value="thinkphp">
    <input type="submit" value="提交">
</form>

In the controller, we can also use the $this->request->param() method to get the parameters passed in the form. For example:

<code><pre class='brush:php;toolbar:false;'>public function index() { $id = $this-&gt;request-&gt;param(&amp;#39;id&amp;#39;); $name = $this-&gt;request-&gt;param(&amp;#39;name&amp;#39;); echo &amp;#39;ID=&amp;#39; . $id . &amp;#39;, Name=&amp;#39; . $name; }</pre>

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, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!