123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class Article extends Validate{
- protected $rule = [
- 'title|标题' => 'require',
- 'content|内容' => 'require',
- 'enable' => 'require|checkEnable',
- ];
- protected $message = [
- ];
- protected $scene = [
- ];
- // 自定义验证规则
- protected function checkEnable($value,$rule,$data=[])
- {
- if($data['id'] > 0){
- $info = Db::name('article')->where('id',$data['id'])->find();
- if(!$info){
- return '记录不存在';
- }
- if($info['enable'] == 1){
- return '已发布不能编辑';
- }
- }
- return true;
- }
- }
|