Skip to content

Commit bb150a4

Browse files
authored
Merge pull request #7190 from kenjis/fix-docs-controllers.rst
docs: improve "Auto Routing (Improved)" in controllers.rst
2 parents a3513cf + 82c02fb commit bb150a4

1 file changed

Lines changed: 27 additions & 11 deletions

File tree

user_guide_src/source/incoming/controllers.rst

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,34 @@ class so that it can inherit all its methods.
221221
folders/files in **app/Controllers/**, when a match wasn't found against defined routes.
222222
That's why your folders/files MUST start with a capital letter and the rest MUST be lowercase.
223223

224+
If you want another naming convention you need to manually define it using the
225+
:ref:`Defined Route Routing <defined-route-routing>`.
224226
Here is an example based on PSR-4 Autoloader:
225227

226228
.. literalinclude:: controllers/012.php
227229

228-
If you want another naming convention you need to manually define it using the
229-
:ref:`Defined Route Routing <defined-route-routing>`.
230-
231230
Methods
232231
=======
233232

233+
Method Visibility
234+
-----------------
235+
236+
When you define a method that is executable via HTTP request, the method must be
237+
declared as ``public``.
238+
239+
.. warning:: For security reasons be sure to declare any new utility methods as ``protected`` or ``private``.
240+
241+
Default Method
242+
--------------
243+
234244
In the above example, the method name is ``getIndex()``.
235-
The method (HTTP verb + ``Index()``) is loaded if the **second segment** of the URI is empty.
245+
The method (HTTP verb + ``Index()``) is called the **default method**, and is loaded if the **second segment** of the URI is empty.
236246

237-
**The second segment of the URI determines which method in the
238-
controller gets called.**
247+
Normal Methods
248+
--------------
249+
250+
The second segment of the URI determines which method in the
251+
controller gets called.
239252

240253
Let's try it. Add a new method to your controller:
241254

@@ -247,8 +260,6 @@ Now load the following URL to see the ``getComment()`` method::
247260

248261
You should see your new message.
249262

250-
.. warning:: For security reasons be sure to declare any new utility methods as ``protected`` or ``private``.
251-
252263
Passing URI Segments to Your Methods
253264
====================================
254265

@@ -263,6 +274,10 @@ Your method will be passed URI segments 3 and 4 (``'sandals'`` and ``'123'``):
263274

264275
.. literalinclude:: controllers/022.php
265276

277+
.. note:: If there are more parameters in the URI than the method parameters,
278+
Auto Routing (Improved) does not execute the method, and it results in 404
279+
Not Found.
280+
266281
Defining a Default Controller
267282
=============================
268283

@@ -390,13 +405,12 @@ class so that it can inherit all its methods.
390405
folders/files in **app/Controllers/**, when a match wasn't found against defined routes.
391406
That's why your folders/files MUST start with a capital letter and the rest MUST be lowercase.
392407

408+
If you want another naming convention you need to manually define it using the
409+
:ref:`Defined Route Routing <defined-route-routing>`.
393410
Here is an example based on PSR-4 Autoloader:
394411

395412
.. literalinclude:: controllers/012.php
396413

397-
If you want another naming convention you need to manually define it using the
398-
:ref:`Defined Route Routing <defined-route-routing>`.
399-
400414
Methods
401415
=======
402416

@@ -494,6 +508,8 @@ CodeIgniter also permits you to map your URIs using its :ref:`Defined Route Rout
494508
Remapping Method Calls
495509
**********************
496510

511+
.. note:: **Auto Routing (Improved)** does not support this feature intentionally.
512+
497513
As noted above, the second segment of the URI typically determines which
498514
method in the controller gets called. CodeIgniter permits you to override
499515
this behavior through the use of the ``_remap()`` method:

0 commit comments

Comments
 (0)