Home >PHP Framework >ThinkPHP >Some summaries on the use of ThinkPHP6

Some summaries on the use of ThinkPHP6

藏色散人
藏色散人forward
2020-10-30 16:46:023108browse

The following tutorial column of ThinkPHP will introduce to you some summary of the use of ThinkPHP6. I hope it will be helpful to friends in need!

Some summaries on the use of ThinkPHP6

At the beginning of 2020, various disasters hit the earth like a bomb.

During the epidemic, I studied the latest version of the TP framework, ThinkPHP6.0.2, and then did a project.

Summarize the usage experience.

1. Installation

Starting from TP5.1, the official website does not support downloading the framework. You need to use composer

ThinkPHP6Environment requirements: PHP >= 7.1.0

If this is the first installation, under the command line, switch to the WEB root directory and execute the following command:

composer create-project topthink/think tp

2. Multiple applications

TP6 uses a single application by default.

If you want to use multi-app mode, you need to install the multi-app mode extension think-multi-app.

composer require topthink/think-multi-app

 

3. Verification code

TP6 does not have a verification code by default and needs to be installed by yourself.

Install extensionthink-captcha.

composer require topthink/think-captcha

Two ways to use

<p>{:captcha_img()}</p>  
<p><img src="{:captcha_src()}" alt="captcha" /></p>

The first is simple, click to change the verification code directly

The second requires adding a random number

Key point: Open the session! ! !

Assistant function determines the verification code

4. Router omits application name

Normal access path: http://domain name/public/entry file/application/controller class/method

Entry file can be hidden: http://domain name/public/application/controller class/ Method

Modify the index.php file under public

// [ 应用入口文件 ]
namespace think;

require __DIR__ . &#39;/../vendor/autoload.php&#39;;

// 执行HTTP应用并响应
$http = (new App())->http;

$response = $http->name(&#39;index&#39;)->run();

$response->send();

$http->end($response);

 

Specify the application directory as index

You don’t need to add the application name to access it

5. Middleware

Route::rule(&#39;hello/:name&#39;,&#39;hello&#39;)->middleware(\app\middleware\Auth::class);

I hope that a certain routing middleware will be executed globally (regardless of Whether the route matches), you don’t need to define it in the route. You can define it directly in the routing configuration file. For example, add: <pre class="brush:php;gutter:true;">&amp;#39;middleware&amp;#39; =&gt; [ app\middleware\Auth::class, app\middleware\Check::class, ],</pre> to the

config/route.php

configuration file. In this way, all Requests under this application will execute the Auth and Check middleware.

Continually updated......

The above is the detailed content of Some summaries on the use of ThinkPHP6. For more information, please follow other related articles on the PHP Chinese website!

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