62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
<?php
|
||
// +------------------------------------------------+
|
||
// |http://www.cjango.com |
|
||
// +------------------------------------------------+
|
||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||
// +------------------------------------------------+
|
||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||
// +------------------------------------------------+
|
||
namespace app\common\validate;
|
||
|
||
use think\Config;
|
||
use think\Validate;
|
||
|
||
class Article extends Validate
|
||
{
|
||
|
||
/**
|
||
* 验证规则
|
||
* @var array
|
||
*/
|
||
protected $rule = [
|
||
'title' => 'require|length:4,20|checkDenied',
|
||
'description' => 'require',
|
||
'content' => 'require|checkDenied:',
|
||
'storage_id' => 'require',
|
||
'category_id' => 'require',
|
||
];
|
||
|
||
/**
|
||
* 提示信息
|
||
* @var array
|
||
*/
|
||
protected $message = [
|
||
'title.require' => '标题必须填写',
|
||
'title.length' => '标题长度应在:1-:2位之间',
|
||
'description.require' => '描述必须填写',
|
||
'content.require' => '内容必须填写',
|
||
'storage_id.require' => '必须上传图片',
|
||
'category_id.require' => '分类必须选择',
|
||
];
|
||
|
||
/**
|
||
* 验证场景
|
||
* @var array
|
||
*/
|
||
protected $scene = [
|
||
'add' => ['title', 'description', 'content', 'storage_id', 'category_id'],
|
||
];
|
||
|
||
protected function checkDenied($value, $rule, $data)
|
||
{
|
||
|
||
$find = Config::get('denied');
|
||
foreach ($find as $k => $v) {
|
||
if (substr_count($value, $v)) {
|
||
return '文章中包含非法关键词 ' . $v;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
}
|