1. Go to this page and download the library: Download lazyu/validate library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
public function update(){
$ArticleValidate = new ArticleValidate;
$request_data = [
'id'=>'1',
'title'=>'我是文章的标题',
'content'=>'我是文章的内容',
];
if (!$ArticleValidate->check($request_data)) {
var_dump($ArticleValidate->getError());
}
}
//自定义场景
public function add(){
$ArticleValidate = new ArticleValidate;
$request_data = [
'title'=>'我是文章的标题',
'content'=>'我是文章的内容',
];
if (!$ArticleValidate->scene('add')->check($request_data)) {
var_dump($ArticleValidate->getError());
}
}