安裝了top-think/think-validate
使用官方文檔的例子 參數(shù)正常的時(shí)候不報(bào)錯(cuò),參數(shù)不符合要求的時(shí)候報(bào)錯(cuò)
default.ERROR: 127.0.0.1 POST 0.0.0.0:8787/api/test
Error: Call to a member function has() on null
<?php
namespace app\api\controller;
class TestController
{
public function index()
{
$data = [
'name' => 'thinkphp',
'email' => 'thinkphpqq2.com',
];
$validate = new \app\common\validate\bmdc\TestValidate();
if (!$validate->check($data)) {
var_dump($validate->getError());
}
return success([123]);
}
}
<?php
namespace app\common\validate\bmdc;
use think\Validate;
class TestValidate extends Validate
{
protected $rule = [
'name' => 'require|max:25',
'age' => 'number|between:1,120',
'email' => 'email',
];
protected $message = [
'name.require' => '名稱(chēng)必須',
'name.max' => '名稱(chēng)最多不能超過(guò)25個(gè)字符',
'age.number' => '年齡必須是數(shù)字',
'age.between' => '年齡只能在1-120之間',
'email' => '郵箱格式錯(cuò)誤',
];
}
macos
使用的是Webman-framework v1.5.16
https://github.com/yzh52521/webman-validate
直接卸載think那個(gè)
composer require yzh52521/webman-validate
直接起飛
Could not find package yzh52521/webman-validate. It was however found via repository search, which indicates a consistency issue with the repository.
切換阿里云的?