博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tp5令牌数据无效 解决方法
阅读量:4111 次
发布时间:2019-05-25

本文共 3201 字,大约阅读时间需要 10 分钟。

按照官方的写法,我怎么都是提示令牌数据无效

令牌数据无效:

图片.png

最后各种资料查,最终解决办法如下:

//html
Version:{$Think.version}
//controlleruse think\Controller;class Token extends Controller{ public function index() { if( $this->request->isPost() ) { $data = [ 'account' => $this->request->param('account' , null) , 'password' => $this->request->param('password' , null) , '__token__'=>$this->request->param('__token__',null) ];// dump($data);die; $validate = new \app\test\validate\Token; if( !$validate->check($data) ) { echo $validate->getError(); } else { echo "ok"; } } return $this->fetch(); }}//validatenamespace app\test\validate;use think\Validate;class Token extends Validate{ protected $rule = [ 'account' => 'require|length:6:7|token' , 'password' => 'require|max:6' , ];}

成功:

图片.png

另一个控制器验证例子 tp5.0.10

{:token()} username:
password:
password_confirmation:
public function save(Request $request)    {//                halt($request->param());        $result = $this->validate(            [                'username'   => $request->param('username') ,                'password'   => $request->param('password') ,                'repassword' => $request->param('repassword') ,                '__token__'=>$request->param('__token__') //必须            ] ,            [                'username'   => 'require|min:3|unique:user|token' ,//验证user模型唯一 //必须                'password'   => 'require|min:3' ,                'repassword' => 'require|min:3|confirm:password'            ],            [                'username.token'=>'请勿重复提交数据' //令牌不正确的返回信息,默认是“令牌数据无效”            ]        );        if( true !== $result ) {            halt($result);        }        $user = \app\common\model\User::create([            'username' => $request->param('username') ,            'password' => MD5($request->param('password'))        ]);        if( !$user ) {            halt($user);        }        else {            /*session('uid',$user->id);            dump('自动登录');            return redirect('index/user/index');*/        }    }

更新数据使用令牌

public function update(Request $request , $id)    {        //单独更新        $info = \app\common\model\WashCardCate::get(['id' => $id]);        $data = input('post.');        $info->title = $data['title'];        $info->note = $data['note'];        $info->start_time = strtotime($data['start_time']);        $info->end_time = strtotime($data['end_time']);        $info->count = $data['count'];        $info->car_id = implode(',' , $data['car_id']);        $info->wash_id = implode(',' , $data['wash_id']);        $info->__token__ = input('__token__');//这里        //        dump($info);die;        $validate = new \app\common\validate\WashCardCate();        $result = $validate->check($info);        if( false === $result ) {            return $this->error($validate->getError());        }        $info->save();        return $this->success('ok' , url('index'));    }

转载地址:http://vhrsi.baihongyu.com/

你可能感兴趣的文章
Letter Combinations of a Phone Number
查看>>
Single Number II --出现一次的数(重)
查看>>
Valid Parentheses --括号匹配
查看>>
Remove Element--原地移除重复元素
查看>>
Remove Duplicates from Sorted Array--从有序数组中移除重复元素
查看>>
Count and Say
查看>>
Gas Station
查看>>
Palindrome Partitioning --回文切割 深搜(重重)
查看>>
Valid Palindrome 简单的回文判断
查看>>
Pascal's Triangle -- 生成杨辉三角
查看>>
Pascal's Triangle II 生成杨辉三角中的某行
查看>>
Minimum Depth of Binary Tree -- 二叉树的最小深度 DFS 加剪枝
查看>>
Climbing Stairs 爬楼梯方法 动态规划
查看>>
Merge Two Sorted Lists 合并两个有序链表
查看>>
pow(x,n) 为什么错这么多次
查看>>
Jump Game 动态规划
查看>>
Binary Tree Maximum Path Sum 自底向上求解(重重重重)
查看>>
Subsets 深搜
查看>>
Subsets II
查看>>
Edit Distance 字符串距离(重重)
查看>>