文档写的很详细 安装 · ThinkPHP6.0完全开发手册 · 看云
1、要求
- PHP >= 7.2.5
2、安装composer
如果遇到问题
在cmd命令下运行即可
set http_proxy=0
再次运行安装命令就成功安装了
安装详细过程文档有。
3、测试
<?php
namespace app\controller;
use app\BaseController;
use think\facade\Request;
class Index extends BaseController
{
public function index()
{
return 'index';
}
public function test($name = 'ThinkPHP6')
{
$arr = Request::param();//获取全部变量
$id = Request::param('id');
var_dump($arr);
var_dump($id);
return 'hello,' . $name;
}
}
post:
get:
http://tp6.com/index/test/name/123/id/456
接收参数成功。
4、链接数据库
当然首先配置数据库
1).env里配置
APP_DEBUG = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = map_edit
USERNAME = root
PASSWORD = root
HOSTPORT = 3306
CHARSET = utf8
DEBUG = true[LANG]
default_lang = zh-cn
2)database.php里配置
如果两者都配置以 .env里为主
3)测试方法
控制器:
<?php
namespace app\controller;
use app\BaseController;
use think\facade\Request;
use app\model\User;
class Index extends BaseController
{
public function index()
{
return 'index';
}
public function test($name = 'ThinkPHP6')
{
$arr = Request::param();//获取全部变量
$id = Request::param('id');
var_dump($arr);
var_dump($id);
return 'hello,' . $name;
}
public function dbtest(){
$user = new User();
$res = $user->getUser();
var_dump($res);
}
}
数据模型
<?php
namespace app\model;
use think\Model;
class User extends Model
{
public function getUser() {
$res = User::where('user_name', 'yck')->find();
return $res;
}
}
数据库链接完毕!!