123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace app\portal\validate;
- use app\admin\model\RouteModel;
- use think\Validate;
- class AdminPageValidate extends Validate
- {
- protected $rule = [
- 'post_title' => 'require',
- 'post_alias' => 'checkAlias'
- ];
- protected $message = [
- 'post_title.require' => '页面标题不能为空',
- ];
- protected $scene = [
- ];
-
- protected function checkAlias($value, $rule, $data)
- {
- if (empty($value)) {
- return true;
- }
- if (preg_match("/^\d+$/", $value)) {
- return "别名不能为纯数字!";
- }
- $routeModel = new RouteModel();
- $fullUrl = $routeModel->buildFullUrl('portal/Page/index', ['id' => $data['id']]);
- if (!$routeModel->existsRoute($value, $fullUrl)) {
- return true;
- } else {
- return "别名已经存在!";
- }
- }
- }
|