Skip to content

Commit 329d4ea

Browse files
committed
docs: add docs
1 parent 502a33e commit 329d4ea

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

user_guide_src/source/changelogs/v4.4.0.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ Others
8888
the ``Content-Disposition: inline`` header to display the file in the browser.
8989
See :ref:`open-file-in-browser` for details.
9090
- **View:** Added optional 2nd parameter ``$saveData`` on ``renderSection()`` to prevent from auto cleans the data after displaying. See :ref:`View Layouts <creating-a-layout>` for details.
91-
- **Auto Routing (Improved)**: Now you can use URI without a method name like
91+
- **Auto Routing (Improved):** Now you can pass arguments to the the default
92+
controller that is omitted in the URI.
93+
See :ref:`controller-default-controller-fallback` for details.
94+
- **Auto Routing (Improved):** Now you can use URI without a method name like
9295
``product/15`` where ``15`` is an arbitrary number.
9396
See :ref:`controller-default-method-fallback` for details.
9497
- **Filters:** Now you can use Filter Arguments with :ref:`$filters property <filters-filters-filter-arguments>`.

user_guide_src/source/incoming/controllers.rst

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,44 @@ Your method will be passed URI segments 3 and 4 (``'sandals'`` and ``'123'``):
274274

275275
.. literalinclude:: controllers/022.php
276276

277+
.. _controller-default-controller-fallback:
278+
279+
Default Controller Fallback
280+
===========================
281+
282+
.. versionadded:: 4.4.0
283+
284+
If the controller corresponding to the URI segment of the controller name
285+
does not exist, and if the default controller (``Home`` by default) exists in
286+
the directory, the remaining URI segments are passed to the default controller
287+
for execution.
288+
289+
For example, when you have the following default controller ``Home`` in the
290+
**app/Controllers/News** directory:
291+
292+
.. literalinclude:: controllers/025.php
293+
294+
Load the following URL::
295+
296+
example.com/index.php/news/list
297+
298+
The ``News\Home`` controller will be found, and the ``getList()`` method will be
299+
executed.
300+
301+
.. note:: If there is ``App\Controllers\News`` controller, it takes precedence.
302+
The URI segments are searched sequentially and the first controller found
303+
is used.
304+
305+
Load the following URL::
306+
307+
example.com/index.php/news/101
308+
309+
The default ``getIndex()`` method will be passed URI segments 2 (``'101'``):
310+
311+
.. note:: If there are more parameters in the URI than the method parameters,
312+
Auto Routing (Improved) does not execute the method, and it results in 404
313+
Not Found.
314+
277315
.. _controller-default-method-fallback:
278316

279317
Default Method Fallback
@@ -282,8 +320,8 @@ Default Method Fallback
282320
.. versionadded:: 4.4.0
283321

284322
If the controller method corresponding to the URI segment of the method name
285-
does not exist, and if the default method is defined, the URI segments are
286-
passed to the default method for execution.
323+
does not exist, and if the default method is defined, the remaining URI segments
324+
are passed to the default method for execution.
287325

288326
.. literalinclude:: controllers/024.php
289327

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Controllers\News;
4+
5+
use App\Controllers\BaseController;
6+
7+
class Home extends BaseController
8+
{
9+
public function getList()
10+
{
11+
// ...
12+
}
13+
14+
public function getIndex($id = null)
15+
{
16+
// ...
17+
}
18+
}

0 commit comments

Comments
 (0)