diff --git a/system/Router/DefinedRouteCollector.php b/system/Router/DefinedRouteCollector.php index eeae28379d04..f77383fa6cef 100644 --- a/system/Router/DefinedRouteCollector.php +++ b/system/Router/DefinedRouteCollector.php @@ -51,7 +51,9 @@ public function collect(): Generator if (is_string($handler) || $handler instanceof Closure) { if ($handler instanceof Closure) { - $handler = '(Closure)'; + $view = $this->routeCollection->getRoutesOptions($route, $method)['view'] ?? false; + + $handler = $view ? '(View) ' . $view : '(Closure)'; } $routeName = $this->routeCollection->getRoutesOptions($route)['as'] ?? $route; diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 21fa22dda707..3e45d6b95588 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -1101,7 +1101,10 @@ public function view(string $from, string $view, ?array $options = null): RouteC ->setData(['segments' => $data], 'raw') ->render($view, $options); - $this->create('get', $from, $to, $options); + $routeOptions = $options ?? []; + $routeOptions = array_merge($routeOptions, ['view' => $view]); + + $this->create('get', $from, $to, $routeOptions); return $this; } @@ -1649,7 +1652,7 @@ public function resetRoutes() * array{ * filter?: string|list, namespace?: string, hostname?: string, * subdomain?: string, offset?: int, priority?: int, as?: string, - * redirect?: string + * redirect?: int * } * > */ diff --git a/tests/system/Router/DefinedRouteCollectorTest.php b/tests/system/Router/DefinedRouteCollectorTest.php index 619f4386886f..ba74cec1a86a 100644 --- a/tests/system/Router/DefinedRouteCollectorTest.php +++ b/tests/system/Router/DefinedRouteCollectorTest.php @@ -82,7 +82,7 @@ public function testCollect() 'method' => 'get', 'route' => 'about', 'name' => 'about', - 'handler' => '(Closure)', + 'handler' => '(View) pages/about', ], ]; $this->assertSame($expected, $definedRoutes); diff --git a/user_guide_src/source/changelogs/v4.4.0.rst b/user_guide_src/source/changelogs/v4.4.0.rst index 20db5a2d7b38..6b77eac7ecc9 100644 --- a/user_guide_src/source/changelogs/v4.4.0.rst +++ b/user_guide_src/source/changelogs/v4.4.0.rst @@ -83,8 +83,17 @@ Enhancements Commands ======== -- Now ``spark routes`` command can specify the host in the request URL. - See :ref:`routing-spark-routes-specify-host`. +- **spark routes:** + - Now you can specify the host in the request URL. + See :ref:`routing-spark-routes-specify-host`. + - It shows view files of :ref:`view-routes` in *Handler* like the following: + + +---------+-------------+------+------------------------------+----------------+---------------+ + | Method | Route | Name | Handler | Before Filters | After Filters | + +---------+-------------+------+------------------------------+----------------+---------------+ + | GET | about | ยป | (View) pages/about | | toolbar | + +---------+-------------+------+------------------------------+----------------+---------------+ + Testing ======= @@ -151,6 +160,7 @@ Others - **Error Handling:** Now you can use :ref:`custom-exception-handlers`. - **RedirectException:** can also take an object that implements ResponseInterface as its first argument. - **RedirectException:** implements ResponsableInterface. +- **DebugBar:** Now :ref:`view-routes` are displayed in *DEFINED ROUTES* on the *Routes* tab. Message Changes ***************