Blogger Information
Blog 4
fans 0
comment 0
visits 2358
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
5月25日作业
clin
Original
496 people have browsed it

验证器类实例

<?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(){

	}
}

运行实例 »

点击 "运行实例" 按钮查看在线实例

1527347877331004.jpg

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post