PHP code example of lazyu / validate

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/ */

    

lazyu / validate example snippets



namespace App\Validate;

/**
 * 文章验证器
 */
class ArticleValidate {
    //验证规则
    protected $rule =[
        'id'=>'    'id. ];

    //自定义场景
    protected $scene = [
        'add'=>"title,content",
        'edit'=> ['id','title','content'],
    ];
}

public function update(){

        $ArticleValidate = new ArticleValidate;

        $request_data = [
            'id'=>'1',
            'title'=>'我是文章的标题',
            'content'=>'我是文章的内容',
        ];

        if (!$ArticleValidate->check($request_data)) {
           var_dump($ArticleValidate->getError());
        }

    }

//自定义场景
    protected $scene = [
        'add'=>"title,content",
        'edit'=> ['id','title','content'],
    ];

//自定义场景
public function add(){

        $ArticleValidate = new ArticleValidate;

        $request_data = [
            'title'=>'我是文章的标题',
            'content'=>'我是文章的内容',
        ];

        if (!$ArticleValidate->scene('add')->check($request_data)) {
           var_dump($ArticleValidate->getError());
        }

    }

$Validate = new Validate;
   
           $request_data = [
               'title'=>'我是文章的标题',
               'content'=>'我是文章的内容',
           ];
   
           $rule =[
               'id'=>'    'title.->getError());
           }