笔记笔记
  • Home
  • AI&ML
  • Example
  • Zoo
  • 关于
⌘ K
PHP 笔记
笔记
url 编码
ThinkPHP
ThinkPHP 笔记
阿里云 域名 云解析
PhpStorm
PhpStorm 非 static 方法 'where' 不应被静态调用,但类具有 '__magic' 方法。
最后更新时间:
Copyright © 2023-2024 | Powered by dumi | GuoDapeng | 冀ICP备20004032号-1 | 冀公网安备 冀公网安备 13024002000293号

TABLE OF CONTENTS

‌
‌
‌
‌

ThinkPHP 笔记

ThinkPHP 小技巧

验证器

<?php
namespace app\admin\validate;
use think\Validate;
class FeeArchivesItemValidate extends Validate
{
protected $rule = [
'amount_type' => ['require', 'in:1,2'],
'approver_name' => ['requireCheckApproverName'],
];
protected $message = [
'amount_type.in' => '类型不合法',
'approver_name' => '审批人名字为必填项',
];
protected $scene = [
'add' => [
'amount_type',
'picture_voucher',
],
];
protected function requireCheckApproverName($value, $rule, $data = []): bool
{
if ($data['amount_type'] != 1) {
if (strlen($value) == 0) return false;
}
return true;
}
}

require 前缀的方法,才能在字段为假值的时候,依然验证。

部署

反向代理伪静态

使用反向代理的时候,有时候会因为路径最后不是 / 结尾,导致错误的 301 重定向。添加 absolute_redirect off; 貌似可以解决。

absolute_redirect off;
location ~* (runtime|application)/{
return 403;
}
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}