想当年6.0刚出来的时候,我用的是出神入化,现在记性不好了长时间也没有用,写文章记录一下问题和重要的笔记。

验证器

生成验证类

php think make:validate User

验证,用的Base控制器官方给出的方法

/**
* 验证成功返回true,否则返回错误信息
* $res string|bool
*/
$res = $this->validate([
    'username' => $username,
], 'User.username');
传入的data数组必须是键值对格式

我这里把基类的验证器返回类型改了一下

try {
    $v->failException(true)->check($data);
}catch (ValidateException $e){
    return $e->getMessage();
}

return true;

JWT解密

try{
    $res = (array)JWT::decode($token, new Key($this->jwt_key, 'HS256'));
}catch (\Exception $e){
    //dump($e->getMessage());

    return false;
}

return (array)$res['data'];
JWT解密成功默认返回的是obj对象,php通常需要转为数组使用。
8
1,801
文章标题:Thinkphp6学习笔记
文章链接:https://yuanm.ren/post/280.html
发布日期:2022-04-26
最后修改时间:2022年05月16日 19:16

取消回复
comment-avatar
2022年05月07日 回复

阿噢,看不懂~

comment-avatar
2022年05月07日 回复

学习方向不同吧ᥬ😂᭄

comment-avatar
2022年05月02日 回复

加油啊,反正我是没学下去

comment-avatar
2022年05月07日 回复

加油加油加油🦀🦀

comment-avatar
2022年05月01日 回复

不明觉厉!

comment-avatar
2022年05月07日 回复

这是在夸我吗?嘿嘿🤤🤤🤤

comment-avatar
2022年04月30日 回复

这是准备进大厂吗

comment-avatar
2022年05月01日 回复

没有,东西太多老是记不住😂

当前浏览器版本低,建议升级