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!
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
ThinkPHP6
Environment 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__ . '/../vendor/autoload.php'; // 执行HTTP应用并响应 $http = (new App())->http; $response = $http->name('index')->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('hello/:name','hello')->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: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;gutter:true;">&#39;middleware&#39; => [
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!