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

Some summaries on the use of ThinkPHP6

藏色散人
Release: 2020-10-30 16:46:49
forward
3114 people have browsed it

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
Copy after login

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
Copy after login

 

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
Copy after login

Two ways to use

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

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);
Copy after login

 

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);
Copy after login

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: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;gutter:true;">&amp;#39;middleware&amp;#39; =&gt; [ app\middleware\Auth::class, app\middleware\Check::class, ],</pre><div class="contentsignin">Copy after login</div></div> to the config/route.php<p> configuration file. In this way, all Requests under this application will execute the <code>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!

Related labels:
source:cnblogs.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template