私人领地

Thinkphp6笔记十三:验证器(控制器验证)

控制器单独验证

<?php
namespace app\admin\controller;
class Index extends AdminBase
{

    public function test(){

        $validate = \think\facade\Validate::rule([
            'name'  => 'require|max:25',
            'email' => 'email',
            'age' => 'require',
        ]);

        $data = [
            'name'  => '3333',
            'email' => 'thinkphp@qq.com',
            'age' => ''
        ];

        if (!$validate->check($data)) {
            print_r($validate->getError());
            dump($validate->getError());
        }

    }

}

 

 

************************************************

Thinkphp高级交QQ流群:101766150

作者:狂奔的蜗牛

转载请注明出处

************************************************

posted @ 2020-04-08 16:54  狂奔的蜗牛Snails  阅读(2357)  评论(0编辑  收藏  举报