Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于验证器中场景属性 currentScene 在check 之后的清空问题 #11

Open
chenye2017 opened this issue Dec 15, 2019 · 1 comment

Comments

@chenye2017
Copy link

验证器的核心check方法中,会有对场景的判断

// 获取场景定义()
$this->getScene($scene);

//
protected function getScene($scene = '')
{
if (empty($scene)) {
// 读取指定场景
$scene = $this->currentScene;
}

是否有考虑过check 之后,属性currentScene 回归成 null,要不然如果连续两次调用验证器,上次的scene 会带入下一次,感觉并不是太好,比如先验证是否有id (edit 情况), 如果id 不存在,则验证 默认的情况。

像这样,我只是调用validate 方法,但是scene : edit 会携带着进入下次 validate 方法调用
$result = $this->validate(
[
'name' => 'thinkphp',
'email' => 'thinkphp@qq.com',
],
'app\index\validator\User.edit');

@chenye2017
Copy link
Author

看了validate make 静态调用能解决上述问题,通过每次new self,上面提到的只是使用check时候的一些看法意见

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant