From 766c410fe43f9ee29e4550ab559dcf30f710e8e7 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 9 Sep 2016 20:37:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BRoute=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 7eb6d3a7..9e5a350b 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1336,22 +1336,31 @@ class Route $bind = []; foreach ($option['bind_model'] as $key => $val) { if ($val instanceof \Closure) { - $bind[$key] = call_user_func_array($val, [$matches]); + $result = call_user_func_array($val, [$matches]); } else { if (is_array($val)) { - parse_str($val[1], $fields); - $model = $val[0]; + $fields = explode('&', $val[1]); + $model = $val[0]; } else { $fields = ['id']; $model = $val; } $where = []; + $match = true; foreach ($fields as $field) { - if (isset($matches[$field])) { + if (!isset($matches[$field])) { + $match = false; + break; + } else { $where[$field] = $matches[$field]; } } - $bind[$key] = $model::where($where)->find(); + if ($match) { + $result = $model::where($where)->findOrFail(); + } + } + if (!empty($result)) { + $bind[$key] = $result; } } $matches = array_merge($matches, $bind);