Home PHP Framework ThinkPHP How to pass parameters in thinkphp

How to pass parameters in thinkphp

Apr 21, 2023 am 11:20 AM

ThinkPHP is a PHP open source framework based on MVC architecture. There are many ways to pass parameters. Here are some commonly used methods.

  1. Passing parameters in GET method
    The parameters passed in the page address bar are obtained through the $_GET global variable.

For example: http://localhost/index.php/Home/Index/index?id=1

It can be obtained in the controller like this: $id = $_GET[ 'id'];

  1. POST parameter transmission
    During the form submission process, data is obtained through the $_POST global variable.

For example: there is an input box in the form whose name attribute is age. It can be obtained in the controller like this: $age = $_POST['age'];

  1. URL address passing parameters

For example: Generate route in the controller:

$url = url('index/details', ['id' => 1] );

Access in routing:

public function details($id)
{

echo $id;
Copy after login

}

  1. passed in SESSION mode Parameters

For example: Assign a value in a page: session('username', 'tom');

Can be obtained in the controller like this: $username = session(' username');

  1. Pass parameters via COOKIES

For example: assign a value in a page: cookie('username', 'tom', 3600);

It can be obtained in the controller like this: $username = cookie('username');

  1. REQUEST way to pass parameters

This is a more flexible way method, it supports both GET and POST methods.

For example: $id = request()->param('id');

Summary

These are relatively common methods of passing parameters, allowing developers to More flexible and convenient use in projects. In project development, we need to flexibly choose the appropriate way to transfer parameters based on the actual situation.

The above is the detailed content of How to pass parameters in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)