Cannot access protected property validate $scene
程序员文章站
2023-11-06 17:32:52
tp5验证场景报错:Cannot access protected property app\common\validate\User::$scene ......
thinkphp验证场景报错:cannot access protected property app\common\validate\user::$scene
tp版本:5.0.24
上代码:
$validate = loader::validate('user'); $validate->scene = "create";
已经在验证器里面定义了场景,但是不能直接去调用
protected表示受保护的,只有本类或子类或父类中可以访问
protected $scene = [ 'create' => ['name'], ];
看了一下thinkphp框架的源码,发现原来是这么调用的:
$validate->check($params,[],'create');