validate的场景可以使用回调方法(支持闭包)而不是固定的字段

This commit is contained in:
thinkphp
2016-03-21 14:47:39 +08:00
parent 74b0c76870
commit 2603178195

View File

@@ -256,9 +256,14 @@ class Validate
$title = $key;
}
// 场景检测
if (!empty($scene) && !in_array($key, $scene)) {
continue;
if (!empty($scene)) {
if ($scene instanceof \Closure && call_user_func_array($scene, [$key, &$data])) {
continue;
} elseif (is_array($scene) && !in_array($key, $scene)) {
continue;
}
}
// 获取数据 支持二维数组
$value = $this->getDataValue($data, $key);