@@ -13,11 +13,27 @@ What is a Controller?
1313
1414A Controller is simply a class file that handles a HTTP request. :doc: `URI Routing <routing >` associates a URI with a controller.
1515
16+ Every controller you create should extend ``BaseController `` class.
17+ This class provides several features that are available to all of your controllers.
18+
19+ Constructor
20+ ***********
21+
22+ The CodeIgniter's Controller has a special constructor ``initController() ``.
23+ It will be called by the framework after PHP's constructor ``__construct() `` execution.
24+
25+ If you want to override the ``initController() ``, don't forget to add ``parent::initController($request, $response, $logger); `` in the method:
26+
27+ .. literalinclude :: controllers/023.php
28+
29+ .. important :: You cannot use ``return`` in the constructor. So ``return redirect()->to('route');`` does not work.
30+
31+ The ``initController() `` method sets the following three properties.
32+
1633Included Properties
1734*******************
1835
19- Every controller you create should extend ``CodeIgniter\Controller `` class.
20- This class provides several features that are available to all of your controllers.
36+ The CodeIgniter's Controller provides these properties.
2137
2238**Request Object **
2339
@@ -95,19 +111,22 @@ The method accepts an array of data to validate in the first parameter:
95111
96112.. literalinclude :: controllers/006.php
97113
98- Private methods
99- ***************
114+ Protecting Methods
115+ ******************
100116
101117In some cases, you may want certain methods hidden from public access.
102118To achieve this, simply declare the method as ``private `` or ``protected ``.
103- That will prevent it from being served by a URL request. For example,
104- if you were to define a method like this for the ``Helloworld `` controller:
119+ That will prevent it from being served by a URL request.
120+
121+ For example, if you were to define a method like this for the ``Helloworld `` controller:
105122
106123.. literalinclude :: controllers/007.php
107124
108- then trying to access it using the following URL will not work::
125+ and to define a route (``helloworld/utitilty ``) for the method. Then trying to access it using the following URL will not work::
126+
127+ example.com/index.php/helloworld/utility
109128
110- example.com/index.php/helloworld/utility/
129+ Auto-routing also will not work.
111130
112131.. _controller-auto-routing-improved :
113132
0 commit comments