From 33404d6fcaba20644fe2ee4b43e331e1ba498c8e Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 28 Feb 2018 15:00:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E9=BB=98=E8=AE=A4=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E7=9A=84=E8=87=AA=E5=8A=A8=E8=AF=86=E5=88=AB=20?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=A0=B9=E6=8D=AE=E6=96=B9=E6=B3=95=E5=90=8D?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=BD=AC=E6=8D=A2=E4=B8=BA=E5=B0=8F=E5=86=99?= =?UTF-8?q?+=E4=B8=8B=E5=88=92=E7=BA=BF=20=E4=B8=8D=E5=8F=97URL=E5=BD=B1?= =?UTF-8?q?=E5=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.php | 6 ++++++ library/think/Controller.php | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/helper.php b/helper.php index 12683cfd..b568dab1 100644 --- a/helper.php +++ b/helper.php @@ -443,6 +443,12 @@ if (!function_exists('view')) { */ function view($template = '', $vars = [], $replace = [], $code = 200) { + if ('' === $template) { + $trace = debug_backtrace(false, 2); + $suffix = Config::get('action_suffix'); + $action = $suffix ? substr($trace[1]['function'], 0, -strlen($suffix)) : $trace[1]['function']; + $template = Loader::parseName($action); + } return Response::create($template, 'view', $code)->replace($replace)->assign($vars); } } diff --git a/library/think/Controller.php b/library/think/Controller.php index e446e58d..43044de7 100644 --- a/library/think/Controller.php +++ b/library/think/Controller.php @@ -52,7 +52,7 @@ class Controller */ public function __construct(Request $request = null) { - $this->view = View::instance(Config::get('template'), Config::get('view_replace_str')); + $this->view = View::instance(Config::get('template'), Config::get('view_replace_str')); $this->request = is_null($request) ? Request::instance() : $request; // 控制器初始化 @@ -117,6 +117,13 @@ class Controller */ protected function fetch($template = '', $vars = [], $replace = [], $config = []) { + if ('' === $template) { + $trace = debug_backtrace(false, 2); + $suffix = Config::get('action_suffix'); + $action = $suffix ? substr($trace[1]['function'], 0, -strlen($suffix)) : $trace[1]['function']; + $template = Loader::parseName($action); + } + return $this->view->fetch($template, $vars, $replace, $config); } @@ -202,9 +209,15 @@ class Controller } // 批量验证 - if ($batch || $this->batchValidate) $v->batch(true); + if ($batch || $this->batchValidate) { + $v->batch(true); + } + // 设置错误信息 - if (is_array($message)) $v->message($message); + if (is_array($message)) { + $v->message($message); + } + // 使用回调验证 if ($callback && is_callable($callback)) { call_user_func_array($callback, [$v, &$data]);