migration的安裝
thinkphp5 migration 默認(rèn)是沒(méi)有安裝的,需要用composer 安裝下。
composer require topthink/think-migration
我的composer 不是全局安裝的,omg。
windows下安裝的把composer.phar加入到環(huán)境變量的path中就可以了。
composer 安裝migration時(shí)報(bào)錯(cuò) Your requirements could not be resolved to an installable set of packages.
經(jīng)查詢,是我的thinkphp5 framework不是6.0,所有安裝migration需要選滿足框架的版本,就向下選了v2.0.3,安裝時(shí)候的命令需要帶上版本號(hào),
composer require topthink/think-migration "v2.0.3"
使用方法:
https://www.kancloud.cn/manual/thinkphp5/215850
Request的不同
引入不同使用不同
- use think\facade\Request;
<?php
namespace app\admin\controller;
use think\Controller;
use think\facade\Request;
use \app\admin\model\Admin;
class Login extends Controller
{
/**
* 登錄
* @return \think\Response
*/
public function signin(Request $request)
{
if($request->isGet()){
return view('signin',['title'=>'*登錄*']);
}
if($request->isPost()){
// todo
}
}
- use think\Request;
<?php
namespace app\admin\controller;
use think\Controller;
use think\Request;
use \app\admin\model\Admin;
class Login extends Controller
{
/**
* 登錄
* @return \think\Response
*/
public function signin()
{
if(Request::isGet()){
return view('signin',['title'=>'*登錄*']);
}
if(Request::isPost()){
// todo
}
}
命令行
使用php think 可以展示出可用的命令,這laravel的php artisan大致差不多的感覺(jué)。
驗(yàn)證器
可以定義不同的驗(yàn)證場(chǎng)景,為每個(gè)想要驗(yàn)證的方法定義一個(gè)場(chǎng)景。
Validate:
/**
* 定義驗(yàn)證場(chǎng)景
*/
protected $scene = [
'signin' => ['username', 'password'],
];
驗(yàn)證:
$result = $this->validate($data, 'Admin.signin');
if(true !== $result) {
$this->error($result);
}