summaryrefslogtreecommitdiffstats
path: root/user_guide/general/controllers.html
diff options
context:
space:
mode:
authorphilsturgeon <devnull@localhost>2011-06-15 17:00:03 +0200
committerphilsturgeon <devnull@localhost>2011-06-15 17:00:03 +0200
commit0fe54dbaf89a8337d27b9203f74891cf1a799715 (patch)
treece168b3c24788e5a4a31e0cc65b64f54e25ee8a2 /user_guide/general/controllers.html
parent3a43c7adae7737d68a0eeca663cc2dd3fc5b0cf3 (diff)
parent3ef65bd7491f847fecdab1acc9687f0e90eee09b (diff)
Merged Alex Bilbies MSSQL changes.
Diffstat (limited to 'user_guide/general/controllers.html')
-rw-r--r--user_guide/general/controllers.html56
1 files changed, 28 insertions, 28 deletions
diff --git a/user_guide/general/controllers.html b/user_guide/general/controllers.html
index 91e700aba..01ef3d1ff 100644
--- a/user_guide/general/controllers.html
+++ b/user_guide/general/controllers.html
@@ -28,7 +28,7 @@
<div id="masthead">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
-<td><h1>CodeIgniter User Guide Version 2.0.0</h1></td>
+<td><h1>CodeIgniter User Guide Version 2.0.2</h1></td>
<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
</tr>
</table>
@@ -91,14 +91,14 @@ Controllers
<a name="hello"></a>
<h2>Let's try it:&nbsp; Hello World!</h2>
-<p>Let's create a simple controller so you can see it in action. Using your text editor, create a file called <dfn>blog.php</dfn>, and put the following code in it:</p>
+<p>Let's create a simple controller so you can see it in action. Using your text editor, create a file called <dfn>blog.php</dfn>, and put the following code in it:</p>
<textarea class="textarea" style="width:100%" cols="50" rows="10">
&lt;?php
class Blog extends CI_Controller {
- function index()
+ public function index()
{
echo 'Hello World!';
}
@@ -116,7 +116,7 @@ class Blog extends CI_Controller {
<p>If you did it right, you should see <samp>Hello World!</samp>.</p>
-<p>Note: Class names must start with an uppercase letter. In other words, this is valid:</p>
+<p>Note: Class names must start with an uppercase letter. In other words, this is valid:</p>
<code>&lt;?php<br />
class <var>Blog</var> extends CI_Controller {<br />
@@ -139,26 +139,26 @@ class <var>blog</var> extends CI_Controller {<br />
<a name="functions"></a>
<h2>Functions</h2>
-<p>In the above example the function name is <dfn>index()</dfn>. The "index" function is always loaded by default if the
-<strong>second segment</strong> of the URI is empty. Another way to show your "Hello World" message would be this:</p>
+<p>In the above example the function name is <dfn>index()</dfn>. The "index" function is always loaded by default if the
+<strong>second segment</strong> of the URI is empty. Another way to show your "Hello World" message would be this:</p>
<code>example.com/index.php/<var>blog</var>/<samp>index</samp>/</code>
<p><strong>The second segment of the URI determines which function in the controller gets called.</strong></p>
-<p>Let's try it. Add a new function to your controller:</p>
+<p>Let's try it. Add a new function to your controller:</p>
<textarea class="textarea" style="width:100%" cols="50" rows="15">
&lt;?php
class Blog extends CI_Controller {
- function index()
+ public function index()
{
echo 'Hello World!';
}
- function comments()
+ public function comments()
{
echo 'Look at this!';
}
@@ -187,7 +187,7 @@ class Blog extends CI_Controller {
&lt;?php<br />
class Products extends CI_Controller {<br />
<br />
-&nbsp;&nbsp;&nbsp;&nbsp;function shoes($sandals, $id)<br />
+&nbsp;&nbsp;&nbsp;&nbsp;public function shoes($sandals, $id)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo $sandals;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo $id;<br />
@@ -204,7 +204,7 @@ passed to your function will be the re-routed ones.</p>
<h2>Defining a Default Controller</h2>
<p>CodeIgniter can be told to load a default controller when a URI is not present,
-as will be the case when only your site root URL is requested. To specify a default controller, open
+as will be the case when only your site root URL is requested. To specify a default controller, open
your <dfn>application/config/routes.php</dfn> file and set this variable:</p>
<code>$route['default_controller'] = '<var>Blog</var>';</code>
@@ -220,18 +220,18 @@ specifying any URI segments you'll see your Hello World message by default.</p>
<p>As noted above, the second segment of the URI typically determines which function in the controller gets called.
CodeIgniter permits you to override this behavior through the use of the <kbd>_remap()</kbd> function:</p>
-<code>function _remap()<br />
+<code>public function _remap()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;// Some code here...<br />
}</code>
<p class="important"><strong>Important:</strong>&nbsp; If your controller contains a function named <kbd>_remap()</kbd>, it will <strong>always</strong>
-get called regardless of what your URI contains. It overrides the normal behavior in which the URI determines which function is called,
+get called regardless of what your URI contains. It overrides the normal behavior in which the URI determines which function is called,
allowing you to define your own function routing rules.</p>
<p>The overridden function call (typically the second segment of the URI) will be passed as a parameter to the <kbd>_remap()</kbd> function:</p>
-<code>function _remap(<var>$method</var>)<br />
+<code>public function _remap(<var>$method</var>)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ($method == 'some_method')<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
@@ -245,10 +245,10 @@ allowing you to define your own function routing rules.</p>
<p>Any extra segments after the method name are passed into <kbd>_remap()</kbd> as an optional second parameter. This array can be used in combination with PHP's <a href="http://php.net/call_user_func_array">call_user_func_array</a> to emulate CodeIgniter's default behavior.</p>
-<code>function _remap($method, $params = array())<br />
+<code>public function _remap($method, $params = array())<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;$method = 'process_'.$method;<br />
-&nbsp;&nbsp;&nbsp;&nbsp;if (method_exists($this, $method)<br />
+&nbsp;&nbsp;&nbsp;&nbsp;if (method_exists($this, $method))<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return call_user_func_array(array($this, $method), $params);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
@@ -259,9 +259,9 @@ allowing you to define your own function routing rules.</p>
<a name="output"></a>
<h2>Processing Output</h2>
-<p>CodeIgniter has an output class that takes care of sending your final rendered data to the web browser automatically. More information on this can be found in the
-<a href="views.html">Views</a> and <a href="../libraries/output.html">Output class</a> pages. In some cases, however, you might want to
-post-process the finalized data in some way and send it to the browser yourself. CodeIgniter permits you to
+<p>CodeIgniter has an output class that takes care of sending your final rendered data to the web browser automatically. More information on this can be found in the
+<a href="views.html">Views</a> and <a href="../libraries/output.html">Output class</a> pages. In some cases, however, you might want to
+post-process the finalized data in some way and send it to the browser yourself. CodeIgniter permits you to
add a function named <dfn>_output()</dfn> to your controller that will receive the finalized output data.</p>
<p><strong>Important:</strong>&nbsp; If your controller contains a function named <kbd>_output()</kbd>, it will <strong>always</strong>
@@ -270,12 +270,12 @@ be called by the output class instead of echoing the finalized data directly. Th
<p>Here is an example:</p>
<code>
-function _output($output)<br />
+public function _output($output)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;echo $output;<br />
}</code>
-<p class="important">Please note that your <dfn>_output()</dfn> function will receive the data in its finalized state. Benchmark and memory usage data will be rendered,
+<p class="important">Please note that your <dfn>_output()</dfn> function will receive the data in its finalized state. Benchmark and memory usage data will be rendered,
cache files written (if you have caching enabled), and headers will be sent (if you use that <a href="../libraries/output.html">feature</a>)
before it is handed off to the _output() function.<br />
<br />
@@ -287,18 +287,18 @@ To have your controller's output cached properly, its <dfn>_output()</dfn> metho
}</code>
If you are using this feature the page execution timer and memory usage stats might not be perfectly accurate
-since they will not take into acccount any further processing you do. For an alternate way to control output <em>before</em> any of the final processing is done, please see
+since they will not take into acccount any further processing you do. For an alternate way to control output <em>before</em> any of the final processing is done, please see
the available methods in the <a href="../libraries/output.html">Output Class</a>.</p>
<a name="private"></a>
<h2>Private Functions</h2>
-<p>In some cases you may want certain functions hidden from public access. To make a function private, simply add an
+<p>In some cases you may want certain functions hidden from public access. To make a function private, simply add an
underscore as the name prefix and it will not be served via a URL request. For example, if you were to have a function like this:</p>
<code>
-function _utility()<br />
+private function _utility()<br />
{<br />
&nbsp;&nbsp;// some code<br />
}</code>
@@ -312,11 +312,11 @@ function _utility()<br />
<a name="subfolders"></a>
<h2>Organizing Your Controllers into Sub-folders</h2>
-<p>If you are building a large application you might find it convenient to organize your controllers into sub-folders. CodeIgniter permits you to do this.</p>
+<p>If you are building a large application you might find it convenient to organize your controllers into sub-folders. CodeIgniter permits you to do this.</p>
<p>Simply create folders within your <dfn>application/controllers</dfn> directory and place your controller classes within them.</p>
-<p><strong>Note:</strong>&nbsp; When using this feature the first segment of your URI must specify the folder. For example, lets say you have a controller
+<p><strong>Note:</strong>&nbsp; When using this feature the first segment of your URI must specify the folder. For example, lets say you have a controller
located here:</p>
<code>application/controllers/<kbd>products</kbd>/shoes.php</code>
@@ -326,7 +326,7 @@ located here:</p>
<code>example.com/index.php/products/shoes/show/123</code>
<p>Each of your sub-folders may contain a default controller which will be
-called if the URL contains only the sub-folder. Simply name your default controller as specified in your
+called if the URL contains only the sub-folder. Simply name your default controller as specified in your
<dfn>application/config/routes.php</dfn> file</p>
@@ -346,7 +346,7 @@ called if the URL contains only the sub-folder. Simply name your default contro
&lt;?php<br />
class <kbd>Blog</kbd> extends CI_Controller {<br />
<br />
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function <kbd>__construct()</kbd><br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public function <kbd>__construct()</kbd><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<var>parent::__construct();</var><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Your own constructor code<br />