thinkphp8:创建thinkphp项目(thinkphp v8.1.1)
一,用composer创建项目
$ composer create-project topthink/think gsadm
查看的项目版本:
$ php think version
v8.1.1
二,配置nginx访问thinkphp项目
server {
listen 8090;
root /data/thinkphp/gsadm/public;
server_name tpapibase;
index index.php;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?s=$1 last;
break;
}
location / {
index index.html index.php;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
三,开启强制路由:
修改config/route.php
设置url_route_must一项的值为true
如下:
// 是否强制使用路由 //'url_route_must' => false, 'url_route_must' => true,
配置route/app.php
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\facade\Route;
/*
Route::get('think', function () {
return 'hello,ThinkPHP8!';
});
Route::get('hello/:name', 'index/hello');
*/
Route::group('newhouse', function () {
Route::get('add', 'newhouse/add');
Route::get('list', 'newhouse/list');
});
四,创建controller
使用控制器的名称:
修改config/route.php
// 是否使用控制器后缀
'controller_suffix' => true,
创建控制器:
$ php think make:controller Newhouse
Controller:app\controller\NewhouseController created successfully.
在创建好的控制器中添加一个方法 list,如下:
<?php
declare (strict_types = 1);
namespace app\controller;
use think\Request;
class NewhouseController
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function list()
{
return "list";
}
五,测试效果: