Correction status:Uncorrected
Teacher's comments:
<?php namespace app\validator; use think\Validate; class News extends Validate{ protected $rule = [ 'username' => 'require', 'title' => 'require|length:1,20', 'content' => 'length:0,1000' ]; protected $mess = [ 'username.require' => '作者不能为空', 'title.require' => '新闻标题不能为空', 'title.length' => '标题长度在1~20之间', 'content' => '新闻内容长度不超过1000字符' ]; }
点击 "运行实例" 按钮查看在线实例
<?php namespace app\index\controller; use app\validator\News; class Newcon{ public function new1(News $validator){ // 创建数据 $data = [ 'username' => 'Administor', 'title' => '', 'content' => '习近平指出,当前,以互联网、大数据、人工智能为代表的新一代信息技术日新月异,给各国经济社会发展、国家管理、社会治理、人民生活带来重大而深远的影响。' ]; //$validator = new News(); $re = $validator -> check($data); if(!$re){ dump($re); dump($validator -> getError()); }else{ dump($re); return '验证通过'; } } public function new2(){ } }
点击 "运行实例" 按钮查看在线实例