安装了top-think/think-validate
使用官方文档的例子 参数正常的时候不报错,参数不符合要求的时候报错
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' => '名称必须',
'name.max' => '名称最多不能超过25个字符',
'age.number' => '年龄必须是数字',
'age.between' => '年龄只能在1-120之间',
'email' => '邮箱格式错误',
];
}
macos
使用的是Webman-framework v1.5.16
https://github.com/yzh52521/webman-validate
直接卸载think那个
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.
切换阿里云的?
你应该目前用的就是阿里云的 去掉阿里云的 阿里云的好多包都没有 别用阿里云的镜像你试一下 应该就可以了
网络不行,github打不开.
packgist 可以打开的 应该可以下
我也没翻墙可以的
thinkphp的验证器包早就不维护了, 换别的吧