2019-12-26 thinkphp5

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的不同

引入不同使用不同

  1. 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 
        }
    }
  1. 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);
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容