mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
修正scope方法$name参数传入array引起$names变量不存在的异常
1.修正$name为array类型时的BUG 2.范围方法调用支持多参数传入
This commit is contained in:
@@ -978,25 +978,27 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* 命名范围
|
* 命名范围
|
||||||
* @access public
|
* @access public
|
||||||
* @param string|array|Closure $name 命名范围名称 逗号分隔
|
* @param string|array|Closure $name 命名范围名称 逗号分隔
|
||||||
* @param mixed $params 参数调用
|
* @param mixed ...$params 参数调用
|
||||||
* @return Model
|
* @return Model
|
||||||
*/
|
*/
|
||||||
public static function scope($name, $params = [])
|
public static function scope($name)
|
||||||
{
|
{
|
||||||
$model = new static();
|
if ($name instanceof Query) {
|
||||||
$query = $model->db();
|
|
||||||
if ($name instanceof \Closure) {
|
|
||||||
call_user_func_array($name, [ & $query, $params]);
|
|
||||||
} elseif ($name instanceof Query) {
|
|
||||||
return $name;
|
return $name;
|
||||||
} else {
|
|
||||||
if (is_string($name)) {
|
|
||||||
$names = explode(',', $name);
|
|
||||||
}
|
}
|
||||||
foreach ($names as $scope) {
|
$model = new static();
|
||||||
|
$params = func_get_args();
|
||||||
|
$params[0] = $model->db();
|
||||||
|
if ($name instanceof \Closure) {
|
||||||
|
call_user_func_array($name, $params);
|
||||||
|
} elseif (is_string($name)) {
|
||||||
|
$name = explode(',', $name);
|
||||||
|
}
|
||||||
|
if (is_array($name)) {
|
||||||
|
foreach ($name as $scope) {
|
||||||
$method = 'scope' . trim($scope);
|
$method = 'scope' . trim($scope);
|
||||||
if (method_exists($model, $method)) {
|
if (method_exists($model, $method)) {
|
||||||
$model->$method($query, $params);
|
call_user_func_array([$model, $method], $params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user