Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ########### |
| 2 | Controllers |
| 3 | ########### |
| 4 | |
| 5 | Controllers are the heart of your application, as they determine how |
| 6 | HTTP requests should be handled. |
| 7 | |
Joseph Wensley | 5b3ea1a | 2011-10-06 20:54:32 -0400 | [diff] [blame] | 8 | .. contents:: Page Contents |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 9 | |
| 10 | What is a Controller? |
| 11 | ===================== |
| 12 | |
purwandi | 02df61f | 2011-10-07 15:33:40 +0700 | [diff] [blame] | 13 | **A Controller is simply a class file that is named in a way that can be |
| 14 | associated with a URI.** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 15 | |
| 16 | Consider this URI:: |
| 17 | |
| 18 | example.com/index.php/blog/ |
| 19 | |
| 20 | In the above example, CodeIgniter would attempt to find a controller |
| 21 | named blog.php and load it. |
| 22 | |
| 23 | **When a controller's name matches the first segment of a URI, it will |
| 24 | be loaded.** |
| 25 | |
| 26 | Let's try it: Hello World! |
| 27 | ========================== |
| 28 | |
| 29 | Let's create a simple controller so you can see it in action. Using your |
| 30 | text editor, create a file called blog.php, and put the following code |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 31 | in it:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 32 | |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 33 | <?php |
| 34 | class Blog extends CI_Controller { |
| 35 | |
| 36 | public function index() |
| 37 | { |
| 38 | echo 'Hello World!'; |
| 39 | } |
| 40 | } |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 41 | |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 42 | Then save the file to your *application/controllers/* directory. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 43 | |
| 44 | Now visit the your site using a URL similar to this:: |
| 45 | |
| 46 | example.com/index.php/blog/ |
| 47 | |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 48 | If you did it right, you should see: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 49 | |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 50 | Hello World! |
| 51 | |
| 52 | .. important:: Class names must start with an uppercase letter. |
| 53 | |
| 54 | This is valid:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 55 | |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 56 | <?php |
| 57 | class Blog extends CI_Controller { |
| 58 | |
| 59 | } |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 60 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 61 | This is **not** valid:: |
| 62 | |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 63 | <?php |
| 64 | class blog extends CI_Controller { |
| 65 | |
| 66 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 67 | |
| 68 | Also, always make sure your controller extends the parent controller |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 69 | class so that it can inherit all its methods. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 70 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 71 | Methods |
| 72 | ======= |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 73 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 74 | In the above example the method name is ``index()``. The "index" method |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 75 | is always loaded by default if the **second segment** of the URI is |
| 76 | empty. Another way to show your "Hello World" message would be this:: |
| 77 | |
| 78 | example.com/index.php/blog/index/ |
| 79 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 80 | **The second segment of the URI determines which method in the |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 81 | controller gets called.** |
| 82 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 83 | Let's try it. Add a new method to your controller:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 84 | |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 85 | <?php |
| 86 | class Blog extends CI_Controller { |
| 87 | |
| 88 | public function index() |
| 89 | { |
| 90 | echo 'Hello World!'; |
| 91 | } |
| 92 | |
| 93 | public function comments() |
| 94 | { |
| 95 | echo 'Look at this!'; |
| 96 | } |
| 97 | } |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 98 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 99 | Now load the following URL to see the comment method:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 100 | |
| 101 | example.com/index.php/blog/comments/ |
| 102 | |
| 103 | You should see your new message. |
| 104 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 105 | Passing URI Segments to your methods |
| 106 | ==================================== |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 107 | |
| 108 | If your URI contains more then two segments they will be passed to your |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 109 | method as parameters. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 110 | |
vlakoff | 3567246 | 2013-02-15 01:36:04 +0100 | [diff] [blame] | 111 | For example, let's say you have a URI like this:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 112 | |
| 113 | example.com/index.php/products/shoes/sandals/123 |
| 114 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 115 | Your method will be passed URI segments 3 and 4 ("sandals" and "123"):: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 116 | |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 117 | <?php |
| 118 | class Products extends CI_Controller { |
| 119 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 120 | public function shoes($sandals, $id) |
| 121 | { |
| 122 | echo $sandals; |
| 123 | echo $id; |
| 124 | } |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 125 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 126 | |
| 127 | .. important:: If you are using the :doc:`URI Routing <routing>` |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 128 | feature, the segments passed to your method will be the re-routed |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 129 | ones. |
| 130 | |
| 131 | Defining a Default Controller |
| 132 | ============================= |
| 133 | |
| 134 | CodeIgniter can be told to load a default controller when a URI is not |
| 135 | present, as will be the case when only your site root URL is requested. |
purwandi | 02df61f | 2011-10-07 15:33:40 +0700 | [diff] [blame] | 136 | To specify a default controller, open your **application/config/routes.php** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 137 | file and set this variable:: |
| 138 | |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 139 | $route['default_controller'] = 'blog'; |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 140 | |
| 141 | Where Blog is the name of the controller class you want used. If you now |
| 142 | load your main index.php file without specifying any URI segments you'll |
| 143 | see your Hello World message by default. |
| 144 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 145 | Remapping Method Calls |
| 146 | ====================== |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 147 | |
| 148 | As noted above, the second segment of the URI typically determines which |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 149 | method in the controller gets called. CodeIgniter permits you to override |
| 150 | this behavior through the use of the ``_remap()`` method:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 151 | |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 152 | public function _remap() |
| 153 | { |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 154 | // Some code here... |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 155 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 156 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 157 | .. important:: If your controller contains a method named _remap(), |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 158 | it will **always** get called regardless of what your URI contains. It |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 159 | overrides the normal behavior in which the URI determines which method |
| 160 | is called, allowing you to define your own method routing rules. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 161 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 162 | The overridden method call (typically the second segment of the URI) will |
| 163 | be passed as a parameter to the ``_remap()`` method:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 164 | |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 165 | public function _remap($method) |
| 166 | { |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 167 | if ($method === 'some_method') |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 168 | { |
| 169 | $this->$method(); |
| 170 | } |
| 171 | else |
| 172 | { |
| 173 | $this->default_method(); |
| 174 | } |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 175 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 176 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 177 | Any extra segments after the method name are passed into ``_remap()`` as an |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 178 | optional second parameter. This array can be used in combination with |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 179 | PHP's `call_user_func_array() <http://php.net/call_user_func_array>`_ |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 180 | to emulate CodeIgniter's default behavior. |
| 181 | |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 182 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 183 | |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 184 | public function _remap($method, $params = array()) |
| 185 | { |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 186 | $method = 'process_'.$method; |
| 187 | if (method_exists($this, $method)) |
| 188 | { |
| 189 | return call_user_func_array(array($this, $method), $params); |
| 190 | } |
| 191 | show_404(); |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 192 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 193 | |
| 194 | Processing Output |
| 195 | ================= |
| 196 | |
| 197 | CodeIgniter has an output class that takes care of sending your final |
| 198 | rendered data to the web browser automatically. More information on this |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 199 | can be found in the :doc:`Views <views>` and :doc:`Output Class |
| 200 | <../libraries/output>` pages. In some cases, however, you might want to |
| 201 | post-process the finalized data in some way and send it to the browser |
| 202 | yourself. CodeIgniter permits you to add a method named ``_output()`` |
| 203 | to your controller that will receive the finalized output data. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 204 | |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 205 | .. important:: If your controller contains a method named ``_output()``, |
| 206 | it will **always** be called by the output class instead of |
| 207 | echoing the finalized data directly. The first parameter of the |
| 208 | method will contain the finalized output. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 209 | |
| 210 | Here is an example:: |
| 211 | |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 212 | public function _output($output) |
| 213 | { |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 214 | echo $output; |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 215 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 216 | |
Kevin Smith | d3f9efe | 2013-05-13 16:34:37 -0500 | [diff] [blame] | 217 | .. note:: |
| 218 | |
| 219 | Please note that your ``_output()`` method will receive the |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 220 | data in its finalized state. Benchmark and memory usage data |
| 221 | will be rendered, cache files written (if you have caching |
| 222 | enabled), and headers will be sent (if you use that |
| 223 | :doc:`feature <../libraries/output>`) before it is handed off |
| 224 | to the ``_output()`` method. |
| 225 | To have your controller's output cached properly, its |
| 226 | ``_output()`` method can use:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 227 | |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 228 | if ($this->output->cache_expiration > 0) |
| 229 | { |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 230 | $this->output->_write_cache($output); |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 231 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 232 | |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 233 | If you are using this feature the page execution timer and |
| 234 | memory usage stats might not be perfectly accurate since they |
| 235 | will not take into account any further processing you do. |
| 236 | For an alternate way to control output *before* any of the |
| 237 | final processing is done, please see the available methods |
| 238 | in the :doc:`Output Library <../libraries/output>`. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 239 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 240 | Private methods |
| 241 | =============== |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 242 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 243 | In some cases you may want certain methods hidden from public access. |
| 244 | In order to achieve this, simply declare the method as being private |
| 245 | or protected and it will not be served via a URL request. For example, |
| 246 | if you were to have a method like this:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 247 | |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 248 | private function _utility() |
| 249 | { |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 250 | // some code |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 251 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 252 | |
| 253 | Trying to access it via the URL, like this, will not work:: |
| 254 | |
| 255 | example.com/index.php/blog/_utility/ |
| 256 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 257 | .. note:: Prefixing method names with an underscore will also prevent |
| 258 | them from being called. This is a legacy feature that is left |
| 259 | for backwards-compatibility. |
| 260 | |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 261 | Organizing Your Controllers into Sub-directories |
| 262 | ================================================ |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 263 | |
| 264 | If you are building a large application you might find it convenient to |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 265 | organize your controllers into sub-directories. CodeIgniter permits you |
| 266 | to do this. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 267 | |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 268 | Simply create folders within your *application/controllers/* directory |
| 269 | and place your controller classes within them. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 270 | |
| 271 | .. note:: When using this feature the first segment of your URI must |
vlakoff | 3567246 | 2013-02-15 01:36:04 +0100 | [diff] [blame] | 272 | specify the folder. For example, let's say you have a controller located |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 273 | here:: |
| 274 | |
| 275 | application/controllers/products/shoes.php |
| 276 | |
| 277 | To call the above controller your URI will look something like this:: |
| 278 | |
| 279 | example.com/index.php/products/shoes/show/123 |
| 280 | |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 281 | Each of your sub-directories may contain a default controller which will be |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 282 | called if the URL contains only the sub-folder. Simply name your default |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 283 | controller as specified in your *application/config/routes.php* file. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 284 | |
| 285 | CodeIgniter also permits you to remap your URIs using its :doc:`URI |
| 286 | Routing <routing>` feature. |
| 287 | |
| 288 | Class Constructors |
| 289 | ================== |
| 290 | |
| 291 | If you intend to use a constructor in any of your Controllers, you |
| 292 | **MUST** place the following line of code in it:: |
| 293 | |
| 294 | parent::__construct(); |
| 295 | |
| 296 | The reason this line is necessary is because your local constructor will |
| 297 | be overriding the one in the parent controller class so we need to |
| 298 | manually call it. |
| 299 | |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 300 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 301 | |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 302 | <?php |
| 303 | class Blog extends CI_Controller { |
| 304 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 305 | public function __construct() |
| 306 | { |
| 307 | parent::__construct(); |
| 308 | // Your own constructor code |
| 309 | } |
Derek Jones | e69b456 | 2011-10-05 17:30:50 -0500 | [diff] [blame] | 310 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 311 | |
| 312 | Constructors are useful if you need to set some default values, or run a |
| 313 | default process when your class is instantiated. Constructors can't |
| 314 | return a value, but they can do some default work. |
| 315 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 316 | Reserved method names |
| 317 | ===================== |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 318 | |
| 319 | Since your controller classes will extend the main application |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 320 | controller you must be careful not to name your methods identically to |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 321 | the ones used by that class, otherwise your local functions will |
| 322 | override them. See :doc:`Reserved Names <reserved_names>` for a full |
| 323 | list. |
| 324 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 325 | .. important:: You should also never have a method named identically |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 326 | to its class name. If you do, and there is no ``__construct()`` |
| 327 | method in the same class, then your e.g. ``Index::index()`` |
| 328 | method will be executed as a class constructor! This is a PHP4 |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 329 | backwards-compatibility feature. |
| 330 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 331 | That's it! |
| 332 | ========== |
| 333 | |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 334 | That, in a nutshell, is all there is to know about controllers. |