Skip to content

Commit 4d6e27f

Browse files
committed
bug fix
1 parent 457a900 commit 4d6e27f

2 files changed

Lines changed: 16 additions & 21 deletions

File tree

src/think/View.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,11 @@ private function parseTemplate(string $template)
138138
// 分析模板文件规则
139139
$request = request();
140140

141-
$module = '';
142-
$controller = '';
143-
$action = '';
144-
145-
if ($request->route) {
146-
$requestPath = strtolower($request->route->getPath());
147-
$explode = explode('/', trim($requestPath, '/'));
148-
$module = $explode[0] ?: 'index';
149-
$controller = $explode[1] ?? 'index';
150-
$action = $explode[2] ?? 'index';
151-
} else {
152-
$requestPath = strtolower($request->path());
153-
$explode = explode('/', trim($requestPath, '/'));
154-
$module = $explode[0] ?: 'index';
155-
$controller = $explode[1] ?? 'index';
156-
$action = $explode[2] ?? 'index';
157-
}
141+
$requestPath = strtolower(str_replace('[.html]', '', $request->path()));
142+
$explode = explode('/', trim($requestPath, '/'));
143+
$module = $explode[0] ?: 'index';
144+
$controller = $explode[1] ?? 'index';
145+
$action = $explode[2] ?? 'index';
158146

159147
// 获取视图根目录
160148
if (strpos($template, '@')) {

think/exception/HttpResponseException.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use Webman\Http\Request;
1616
use Webman\Http\Response;
17-
use support\exception\BusinessException;
17+
use Webman\Exception\BusinessException;
1818

1919
/**
2020
* HTTP响应异常
@@ -34,15 +34,22 @@ public function __construct(Response $response)
3434
/**
3535
* Undocumented function
3636
*
37-
* @return Response
37+
* @return Response|null
3838
*/
39-
public function getResponse()
39+
public function getResponse(): ?Response
4040
{
4141
return $this->response;
4242
}
4343

44+
/**
45+
* Render an exception into an HTTP response.
46+
* @param Request $request
47+
* @return Response|null
48+
*/
4449
public function render(Request $request): ?Response
4550
{
46-
return $this->response;
51+
//返回一个新对象,
52+
//避免 App::exceptionResponse() 中 $response->exception($e) 造成循环引用
53+
return new Response($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->rawBody());
4754
}
4855
}

0 commit comments

Comments
 (0)