diff options
author | Derek Allard <derek.allard@ellislab.com> | 2008-11-13 23:59:24 +0100 |
---|---|---|
committer | Derek Allard <derek.allard@ellislab.com> | 2008-11-13 23:59:24 +0100 |
commit | 2067d1a727e7eb5e5ffb40e967f3d1fc4c8a41b2 (patch) | |
tree | a95e01024205837e9580757350d04b233e82503f /user_guide/libraries | |
parent | dd9f932556d3cd45a1d06cc478f40d06b7649a69 (diff) |
Changing EOL style to LF
Diffstat (limited to 'user_guide/libraries')
25 files changed, 8070 insertions, 8070 deletions
diff --git a/user_guide/libraries/benchmark.html b/user_guide/libraries/benchmark.html index 67c361357..9f83a8de5 100644 --- a/user_guide/libraries/benchmark.html +++ b/user_guide/libraries/benchmark.html @@ -1,197 +1,197 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Benchmarking Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Benchmarking Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>Benchmarking Class</h1>
-
-<p>CodeIgniter has a Benchmarking class that is always active, enabling the time difference between any
-two marked points to be calculated.</p>
-
-<p class="important"><strong>Note:</strong> This class is initialized automatically by the system so there is no need to do it manually.</p>
-
-
-<p>In addition, the benchmark is always started the moment the framework is
-invoked, and ended by the output class right before sending the final view to the browser, enabling a very accurate
-timing of the entire system execution to be shown.</p>
-
-
-<h3>Table of Contents</h3>
-
-<ul>
-<li><a href="#using">Using the Benchmark Class</a></li>
-<li><a href="#profiler">Profiling Your Benchmark Points</a></li>
-<li><a href="#execution">Displaying Total Execution Time</a></li>
-<li><a href="#memory">Displaying Memory Consumption</a></li>
-</ul>
-
-
-
-<a name="using"></a>
-<h2>Using the Benchmark Class</h2>
-
-<p>The Benchmark class can be used within your <a href="../general/controllers.html">controllers</a>, <a href="../general/views.html">views</a>, or your <a href="../general/models.html">Models</a>. The process for usage is this:</p>
-
-<ol>
-<li>Mark a start point</li>
-<li>Mark an end point</li>
-<li>Run the "elapsed time" function to view the results</li>
-</ol>
-
-<p>Here's an example using real code:</p>
-
-<code>$this->benchmark->mark('code_start');<br />
-<br />
-// Some code happens here<br />
-<br />
-$this->benchmark->mark('code_end');<br />
-<br />
-echo $this->benchmark->elapsed_time('code_start', 'code_end');</code>
-
-<p class="important"><strong>Note:</strong> The words "code_start" and "code_end" are arbitrary. They are simply words used to set two markers. You can
-use any words you want, and you can set multiple sets of markers. Consider this example:</p>
-
-<code>$this->benchmark->mark('dog');<br />
-<br />
-// Some code happens here<br />
-<br />
-$this->benchmark->mark('cat');<br />
-<br />
-// More code happens here<br />
-<br />
-$this->benchmark->mark('bird');<br />
-<br />
-echo $this->benchmark->elapsed_time('dog', 'cat');<br />
-echo $this->benchmark->elapsed_time('cat', 'bird');<br />
-echo $this->benchmark->elapsed_time('dog', 'bird');</code>
-
-
-<a name="profiler"></a>
-<h2>Profiling Your Benchmark Points</h2>
-
-<p>If you want your benchmark data to be available to the
-<a href="../general/profiling.html">Profiler</a> all of your marked points must be set up in pairs, and
-each mark point name must end with <kbd>_start</kbd> and <kbd>_end</kbd>.
-Each pair of points must otherwise be named identically. Example:</p>
-
-<code>
-$this->benchmark->mark('my_mark<kbd>_start</kbd>');<br />
-<br />
-// Some code happens here...<br />
-<br />
-$this->benchmark->mark('my_mark<kbd>_end</kbd>');
-<br /><br />
-
-$this->benchmark->mark('another_mark<kbd>_start</kbd>');<br />
-<br />
-// Some more code happens here...<br />
-<br />
-$this->benchmark->mark('another_mark<kbd>_end</kbd>');
-</code>
-
-<p>Please read the <a href="../general/profiling.html">Profiler page</a> for more information.</p>
-
-
-<a name="execution"></a>
-<h2>Displaying Total Execution Time</h2>
-
-<p>If you would like to display the total elapsed time from the moment CodeIgniter starts to the moment the final output
-is sent to the browser, simply place this in one of your view templates:</p>
-
-<code><?php echo $this->benchmark->elapsed_time();?></code>
-
-<p>You'll notice that it's the same function used in the examples above to calculate the time between two point, except you are
-<strong>not</strong> using any parameters. When the parameters are absent, CodeIgniter does not stop the benchmark until right before the final
-output is sent to the browser. It doesn't matter where you use the function call, the timer will continue to run until the very end.</p>
-
-<p>An alternate way to show your elapsed time in your view files is to use this pseudo-variable, if you prefer not to use the pure PHP:</p>
-<code>{elapsed_time}</code>
-
-<p class="important"><strong>Note:</strong> If you want to benchmark anything within your controller
-functions you must set your own start/end points.</p>
-
-<a name="memory"></a>
-<h2>Displaying Memory Consumption</h2>
-
-<p>If your PHP installation is configured with --enable-memory-limit, you can display the amount of memory consumed by the entire
-system using the following code in one of your view file:</p>
-
-<code><?php echo $this->benchmark->memory_usage();?></code>
-<p>Note: This function can only be used in your view files. The consumption will reflect the total memory used by the entire app.</p>
-
-<p>An alternate way to show your memory usage in your view files is to use this pseudo-variable, if you prefer not to use the pure PHP:</p>
-<code>{memory_usage}</code>
-
-
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="../general/security.html"> Security</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="calendar.html">Calendaring Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Benchmarking Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Benchmarking Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>Benchmarking Class</h1> + +<p>CodeIgniter has a Benchmarking class that is always active, enabling the time difference between any +two marked points to be calculated.</p> + +<p class="important"><strong>Note:</strong> This class is initialized automatically by the system so there is no need to do it manually.</p> + + +<p>In addition, the benchmark is always started the moment the framework is +invoked, and ended by the output class right before sending the final view to the browser, enabling a very accurate +timing of the entire system execution to be shown.</p> + + +<h3>Table of Contents</h3> + +<ul> +<li><a href="#using">Using the Benchmark Class</a></li> +<li><a href="#profiler">Profiling Your Benchmark Points</a></li> +<li><a href="#execution">Displaying Total Execution Time</a></li> +<li><a href="#memory">Displaying Memory Consumption</a></li> +</ul> + + + +<a name="using"></a> +<h2>Using the Benchmark Class</h2> + +<p>The Benchmark class can be used within your <a href="../general/controllers.html">controllers</a>, <a href="../general/views.html">views</a>, or your <a href="../general/models.html">Models</a>. The process for usage is this:</p> + +<ol> +<li>Mark a start point</li> +<li>Mark an end point</li> +<li>Run the "elapsed time" function to view the results</li> +</ol> + +<p>Here's an example using real code:</p> + +<code>$this->benchmark->mark('code_start');<br /> +<br /> +// Some code happens here<br /> +<br /> +$this->benchmark->mark('code_end');<br /> +<br /> +echo $this->benchmark->elapsed_time('code_start', 'code_end');</code> + +<p class="important"><strong>Note:</strong> The words "code_start" and "code_end" are arbitrary. They are simply words used to set two markers. You can +use any words you want, and you can set multiple sets of markers. Consider this example:</p> + +<code>$this->benchmark->mark('dog');<br /> +<br /> +// Some code happens here<br /> +<br /> +$this->benchmark->mark('cat');<br /> +<br /> +// More code happens here<br /> +<br /> +$this->benchmark->mark('bird');<br /> +<br /> +echo $this->benchmark->elapsed_time('dog', 'cat');<br /> +echo $this->benchmark->elapsed_time('cat', 'bird');<br /> +echo $this->benchmark->elapsed_time('dog', 'bird');</code> + + +<a name="profiler"></a> +<h2>Profiling Your Benchmark Points</h2> + +<p>If you want your benchmark data to be available to the +<a href="../general/profiling.html">Profiler</a> all of your marked points must be set up in pairs, and +each mark point name must end with <kbd>_start</kbd> and <kbd>_end</kbd>. +Each pair of points must otherwise be named identically. Example:</p> + +<code> +$this->benchmark->mark('my_mark<kbd>_start</kbd>');<br /> +<br /> +// Some code happens here...<br /> +<br /> +$this->benchmark->mark('my_mark<kbd>_end</kbd>'); +<br /><br /> + +$this->benchmark->mark('another_mark<kbd>_start</kbd>');<br /> +<br /> +// Some more code happens here...<br /> +<br /> +$this->benchmark->mark('another_mark<kbd>_end</kbd>'); +</code> + +<p>Please read the <a href="../general/profiling.html">Profiler page</a> for more information.</p> + + +<a name="execution"></a> +<h2>Displaying Total Execution Time</h2> + +<p>If you would like to display the total elapsed time from the moment CodeIgniter starts to the moment the final output +is sent to the browser, simply place this in one of your view templates:</p> + +<code><?php echo $this->benchmark->elapsed_time();?></code> + +<p>You'll notice that it's the same function used in the examples above to calculate the time between two point, except you are +<strong>not</strong> using any parameters. When the parameters are absent, CodeIgniter does not stop the benchmark until right before the final +output is sent to the browser. It doesn't matter where you use the function call, the timer will continue to run until the very end.</p> + +<p>An alternate way to show your elapsed time in your view files is to use this pseudo-variable, if you prefer not to use the pure PHP:</p> +<code>{elapsed_time}</code> + +<p class="important"><strong>Note:</strong> If you want to benchmark anything within your controller +functions you must set your own start/end points.</p> + +<a name="memory"></a> +<h2>Displaying Memory Consumption</h2> + +<p>If your PHP installation is configured with --enable-memory-limit, you can display the amount of memory consumed by the entire +system using the following code in one of your view file:</p> + +<code><?php echo $this->benchmark->memory_usage();?></code> +<p>Note: This function can only be used in your view files. The consumption will reflect the total memory used by the entire app.</p> + +<p>An alternate way to show your memory usage in your view files is to use this pseudo-variable, if you prefer not to use the pure PHP:</p> +<code>{memory_usage}</code> + + + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="../general/security.html"> Security</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="calendar.html">Calendaring Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/calendar.html b/user_guide/libraries/calendar.html index 1c8499397..9daf26518 100644 --- a/user_guide/libraries/calendar.html +++ b/user_guide/libraries/calendar.html @@ -1,249 +1,249 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Calendaring Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Calendaring Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-
-
-<h1>Calendaring Class</h1>
-
-<p>The Calendar class enables you to dynamically create calendars. Your calendars can be formatted through the use of a calendar
-template, allowing 100% control over every aspect of its design. In addition, you can pass data to your calendar cells.</p>
-
-<h2>Initializing the Class</h2>
-
-<p>Like most other classes in CodeIgniter, the Calendar class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
-
-<code>$this->load->library('calendar');</code>
-<p>Once loaded, the Calendar object will be available using: <dfn>$this->calendar</dfn></p>
-
-
-<h2>Displaying a Calendar</h2>
-
-<p>Here is a very simple example showing how you can display a calendar:</p>
-
-<code>$this->load->library('calendar');<br />
-<br />
-echo $this->calendar->generate();</code>
-
-<p>The above code will generate a calendar for the current month/year based on your server time.
-To show a calendar for a specific month and year you will pass this information to the calendar generating function:</p>
-
-<code>$this->load->library('calendar');<br />
-<br />
-echo $this->calendar->generate(<kbd>2006</kbd>, <kbd>6</kbd>);</code>
-
-<p>The above code will generate a calendar showing the month of June in 2006. The first parameter specifies the year, the second parameter specifies the month.</p>
-
-<h2>Passing Data to your Calendar Cells</h2>
-
-<p>To add data to your calendar cells involves creating an associative array in which the keys correspond to the days
-you wish to populate and the array value contains the data. The array is passed to the third parameter of the calendar
-generating function. Consider this example:</p>
-
-<code>$this->load->library('calendar');<br />
-<br />
-$data = array(<br />
- 3 => 'http://example.com/news/article/2006/03/',<br />
- 7 => 'http://example.com/news/article/2006/07/',<br />
- 13 => 'http://example.com/news/article/2006/13/',<br />
- 26 => 'http://example.com/news/article/2006/26/'<br />
- );<br />
-<br />
-echo $this->calendar->generate(<kbd>2006</kbd>, <kbd>6</kbd>, <var>$data</var>);</code>
-
-<p>Using the above example, day numbers 3, 7, 13, and 26 will become links pointing to the URLs you've provided.</p>
-
-<p class="important"><strong>Note:</strong> By default it is assumed that your array will contain links.
-In the section that explains the calendar template below you'll see how you can customize
-how data passed to your cells is handled so you can pass different types of information.</p>
-
-
-<h2>Setting Display Preferences</h2>
-
-<p>There are seven preferences you can set to control various aspects of the calendar. Preferences are set by passing an
-array of preferences in the second parameter of the loading function. Here is an example:</p>
-
-
-<code>
-$prefs = array (<br />
- 'start_day' => 'saturday',<br />
- 'month_type' => 'long',<br />
- 'day_type' => 'short'<br />
- );<br />
-<br />
-$this->load->library('calendar', $prefs);<br />
-<br />
-echo $this->calendar->generate();</code>
-
-<p>The above code would start the calendar on saturday, use the "long" month heading, and the "short" day names. More information
-regarding preferences below.</p>
-
-
-
-
-<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
-<tr>
-<th>Preference</th>
-<th>Default Value</th>
-<th>Options</th>
-<th>Description</th>
-</tr><tr>
-<td class="td"><strong>template</strong></td><td class="td">None</td><td class="td">None</td><td class="td">A string containing your calendar template. See the template section below.</td>
-</tr><tr>
-<td class="td"><strong>local_time</strong></td><td class="td">time()</td><td class="td">None</td><td class="td">A Unix timestamp corresponding to the current time.</td>
-</tr><tr>
-<td class="td"><strong>start_day</strong></td><td class="td">sunday</td><td class="td">Any week day (sunday, monday, tuesday, etc.)</td><td class="td">Sets the day of the week the calendar should start on.</td>
-</tr><tr>
-<td class="td"><strong>month_type</strong></td><td class="td">long</td><td class="td">long, short</td><td class="td">Determines what version of the month name to use in the header. long = January, short = Jan.</td>
-</tr><tr>
-<td class="td"><strong>day_type</strong></td><td class="td">abr</td><td class="td">long, short, abr</td><td class="td">Determines what version of the weekday names to use in the column headers. long = Sunday, short = Sun, abr = Su.</td>
-</tr><tr>
-<td class="td"><strong>show_next_prev</strong></td><td class="td">FALSE</td><td class="td">TRUE/FALSE (boolean)</td><td class="td">Determines whether to display links allowing you to toggle to next/previous months. See information on this feature below.</td>
-</tr><tr>
-<td class="td"><strong>next_prev_url</strong></td><td class="td">None</td><td class="td">A URL</td><td class="td">Sets the basepath used in the next/previous calendar links.</td>
-</tr>
-</table>
-
-
-
-<h2>Showing Next/Previous Month Links</h2>
-
-<p>To allow your calendar to dynamically increment/decrement via the next/previous links requires that you set up your calendar
-code similar to this example:</p>
-
-
-<code>$prefs = array (<br />
- 'show_next_prev' => TRUE,<br />
- 'next_prev_url' => 'http://example.com/index.php/calendar/show/'<br />
- );<br />
-<br />
-$this->load->library('calendar', $prefs);<br />
-<br />
-echo $this->calendar->generate(<var>$this->uri->segment(3)</var>, <var>$this->uri->segment(4)</var>);</code>
-
-<p>You'll notice a few things about the above example:</p>
-
-<ul>
-<li>You must set the "show_next_prev" to TRUE.</li>
-<li>You must supply the URL to the controller containing your calendar in the "next_prev_url" preference.</li>
-<li>You must supply the "year" and "month" to the calendar generating function via the URI segments where they appear (Note: The calendar class automatically adds the year/month to the base URL you provide.).</li>
-</ul>
-
-
-
-<h2>Creating a Calendar Template</h2>
-
-<p>By creating a calendar template you have 100% control over the design of your calendar. Each component of your
-calendar will be placed within a pair of pseudo-variables as shown here:</p>
-
-
-<code>
-$prefs['template'] = '<br /><br />
- <dfn>{table_open}</dfn><var><table border="0" cellpadding="0" cellspacing="0"></var><dfn>{/table_open}</dfn><br />
-<br />
- <dfn>{heading_row_start}</dfn><var><tr></var><dfn>{/heading_row_start}</dfn><br />
-<br />
- <dfn>{heading_previous_cell}</dfn><var><th><a href="</var><kbd>{previous_url}</kbd><var>">&lt;&lt;</a></th></var><dfn>{/heading_previous_cell}</dfn><br />
- <dfn>{heading_title_cell}</dfn><var><th colspan="</var><kbd>{colspan}</kbd><var>"></var><kbd>{heading}</kbd><var></th></var><dfn>{/heading_title_cell}</dfn><br />
- <dfn>{heading_next_cell}</dfn><var><th><a href="</var><kbd>{next_url}</kbd><var>">&gt;&gt;</a></th></var><dfn>{/heading_next_cell}</dfn><br />
-<br />
- <dfn>{heading_row_end}</dfn><var></tr></var><dfn>{/heading_row_end}</dfn><br />
-<br />
- <dfn>{week_row_start}</dfn><var><tr></var><dfn>{/week_row_start}</dfn><br />
- <dfn>{week_day_cell}</dfn><var><td></var><dfn>{week_day}</dfn><var></td></var><dfn>{/week_day_cell}</dfn><br />
- <dfn>{week_row_end}</dfn><var></tr></var><dfn>{/week_row_end}</dfn><br />
-<br />
- <dfn>{cal_row_start}</dfn><var><tr></var><dfn>{/cal_row_start}</dfn><br />
- <dfn>{cal_cell_start}</dfn><var><td></var><dfn>{/cal_cell_start}</dfn><br />
-<br />
- <dfn>{cal_cell_content}</dfn><var><a href="</var><kbd>{content}</kbd><var>"></var><kbd>{day}</kbd><var></a></var><dfn>{/cal_cell_content}</dfn><br />
- <dfn>{cal_cell_content_today}</dfn><var><div class="highlight"><a href="</var><kbd>{content}</kbd><var>"></var><kbd>{day}</kbd><var></a></div></var><dfn>{/cal_cell_content_today}</dfn><br />
-<br />
- <dfn>{cal_cell_no_content}</dfn><var></var><kbd>{day}</kbd><var></var><dfn>{/cal_cell_no_content}</dfn><br />
- <dfn>{cal_cell_no_content_today}</dfn><var><div class="highlight"></var><kbd>{day}</kbd><var></div></var><dfn>{/cal_cell_no_content_today}</dfn><br />
-<br />
- <dfn>{cal_cell_blank}</dfn><var>&nbsp;</var><dfn>{/cal_cell_blank}</dfn><br />
-<br />
- <dfn>{cal_cell_end}</dfn><var></td></var><dfn>{/cal_cell_end}</dfn><br />
- <dfn>{cal_row_end}</dfn><var></tr></var><dfn>{/cal_row_end}</dfn><br />
-<br />
- <dfn>{table_close}</dfn><var></table></var><dfn>{/table_close}</dfn><br />
-';<br />
-<br />
-$this->load->library('calendar', $prefs);<br />
-<br />
-echo $this->calendar->generate();</code>
-
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="benchmark.html">Benchmarking Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="config.html">Config Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Calendaring Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Calendaring Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + + + +<h1>Calendaring Class</h1> + +<p>The Calendar class enables you to dynamically create calendars. Your calendars can be formatted through the use of a calendar +template, allowing 100% control over every aspect of its design. In addition, you can pass data to your calendar cells.</p> + +<h2>Initializing the Class</h2> + +<p>Like most other classes in CodeIgniter, the Calendar class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p> + +<code>$this->load->library('calendar');</code> +<p>Once loaded, the Calendar object will be available using: <dfn>$this->calendar</dfn></p> + + +<h2>Displaying a Calendar</h2> + +<p>Here is a very simple example showing how you can display a calendar:</p> + +<code>$this->load->library('calendar');<br /> +<br /> +echo $this->calendar->generate();</code> + +<p>The above code will generate a calendar for the current month/year based on your server time. +To show a calendar for a specific month and year you will pass this information to the calendar generating function:</p> + +<code>$this->load->library('calendar');<br /> +<br /> +echo $this->calendar->generate(<kbd>2006</kbd>, <kbd>6</kbd>);</code> + +<p>The above code will generate a calendar showing the month of June in 2006. The first parameter specifies the year, the second parameter specifies the month.</p> + +<h2>Passing Data to your Calendar Cells</h2> + +<p>To add data to your calendar cells involves creating an associative array in which the keys correspond to the days +you wish to populate and the array value contains the data. The array is passed to the third parameter of the calendar +generating function. Consider this example:</p> + +<code>$this->load->library('calendar');<br /> +<br /> +$data = array(<br /> + 3 => 'http://example.com/news/article/2006/03/',<br /> + 7 => 'http://example.com/news/article/2006/07/',<br /> + 13 => 'http://example.com/news/article/2006/13/',<br /> + 26 => 'http://example.com/news/article/2006/26/'<br /> + );<br /> +<br /> +echo $this->calendar->generate(<kbd>2006</kbd>, <kbd>6</kbd>, <var>$data</var>);</code> + +<p>Using the above example, day numbers 3, 7, 13, and 26 will become links pointing to the URLs you've provided.</p> + +<p class="important"><strong>Note:</strong> By default it is assumed that your array will contain links. +In the section that explains the calendar template below you'll see how you can customize +how data passed to your cells is handled so you can pass different types of information.</p> + + +<h2>Setting Display Preferences</h2> + +<p>There are seven preferences you can set to control various aspects of the calendar. Preferences are set by passing an +array of preferences in the second parameter of the loading function. Here is an example:</p> + + +<code> +$prefs = array (<br /> + 'start_day' => 'saturday',<br /> + 'month_type' => 'long',<br /> + 'day_type' => 'short'<br /> + );<br /> +<br /> +$this->load->library('calendar', $prefs);<br /> +<br /> +echo $this->calendar->generate();</code> + +<p>The above code would start the calendar on saturday, use the "long" month heading, and the "short" day names. More information +regarding preferences below.</p> + + + + +<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder"> +<tr> +<th>Preference</th> +<th>Default Value</th> +<th>Options</th> +<th>Description</th> +</tr><tr> +<td class="td"><strong>template</strong></td><td class="td">None</td><td class="td">None</td><td class="td">A string containing your calendar template. See the template section below.</td> +</tr><tr> +<td class="td"><strong>local_time</strong></td><td class="td">time()</td><td class="td">None</td><td class="td">A Unix timestamp corresponding to the current time.</td> +</tr><tr> +<td class="td"><strong>start_day</strong></td><td class="td">sunday</td><td class="td">Any week day (sunday, monday, tuesday, etc.)</td><td class="td">Sets the day of the week the calendar should start on.</td> +</tr><tr> +<td class="td"><strong>month_type</strong></td><td class="td">long</td><td class="td">long, short</td><td class="td">Determines what version of the month name to use in the header. long = January, short = Jan.</td> +</tr><tr> +<td class="td"><strong>day_type</strong></td><td class="td">abr</td><td class="td">long, short, abr</td><td class="td">Determines what version of the weekday names to use in the column headers. long = Sunday, short = Sun, abr = Su.</td> +</tr><tr> +<td class="td"><strong>show_next_prev</strong></td><td class="td">FALSE</td><td class="td">TRUE/FALSE (boolean)</td><td class="td">Determines whether to display links allowing you to toggle to next/previous months. See information on this feature below.</td> +</tr><tr> +<td class="td"><strong>next_prev_url</strong></td><td class="td">None</td><td class="td">A URL</td><td class="td">Sets the basepath used in the next/previous calendar links.</td> +</tr> +</table> + + + +<h2>Showing Next/Previous Month Links</h2> + +<p>To allow your calendar to dynamically increment/decrement via the next/previous links requires that you set up your calendar +code similar to this example:</p> + + +<code>$prefs = array (<br /> + 'show_next_prev' => TRUE,<br /> + 'next_prev_url' => 'http://example.com/index.php/calendar/show/'<br /> + );<br /> +<br /> +$this->load->library('calendar', $prefs);<br /> +<br /> +echo $this->calendar->generate(<var>$this->uri->segment(3)</var>, <var>$this->uri->segment(4)</var>);</code> + +<p>You'll notice a few things about the above example:</p> + +<ul> +<li>You must set the "show_next_prev" to TRUE.</li> +<li>You must supply the URL to the controller containing your calendar in the "next_prev_url" preference.</li> +<li>You must supply the "year" and "month" to the calendar generating function via the URI segments where they appear (Note: The calendar class automatically adds the year/month to the base URL you provide.).</li> +</ul> + + + +<h2>Creating a Calendar Template</h2> + +<p>By creating a calendar template you have 100% control over the design of your calendar. Each component of your +calendar will be placed within a pair of pseudo-variables as shown here:</p> + + +<code> +$prefs['template'] = '<br /><br /> + <dfn>{table_open}</dfn><var><table border="0" cellpadding="0" cellspacing="0"></var><dfn>{/table_open}</dfn><br /> +<br /> + <dfn>{heading_row_start}</dfn><var><tr></var><dfn>{/heading_row_start}</dfn><br /> +<br /> + <dfn>{heading_previous_cell}</dfn><var><th><a href="</var><kbd>{previous_url}</kbd><var>">&lt;&lt;</a></th></var><dfn>{/heading_previous_cell}</dfn><br /> + <dfn>{heading_title_cell}</dfn><var><th colspan="</var><kbd>{colspan}</kbd><var>"></var><kbd>{heading}</kbd><var></th></var><dfn>{/heading_title_cell}</dfn><br /> + <dfn>{heading_next_cell}</dfn><var><th><a href="</var><kbd>{next_url}</kbd><var>">&gt;&gt;</a></th></var><dfn>{/heading_next_cell}</dfn><br /> +<br /> + <dfn>{heading_row_end}</dfn><var></tr></var><dfn>{/heading_row_end}</dfn><br /> +<br /> + <dfn>{week_row_start}</dfn><var><tr></var><dfn>{/week_row_start}</dfn><br /> + <dfn>{week_day_cell}</dfn><var><td></var><dfn>{week_day}</dfn><var></td></var><dfn>{/week_day_cell}</dfn><br /> + <dfn>{week_row_end}</dfn><var></tr></var><dfn>{/week_row_end}</dfn><br /> +<br /> + <dfn>{cal_row_start}</dfn><var><tr></var><dfn>{/cal_row_start}</dfn><br /> + <dfn>{cal_cell_start}</dfn><var><td></var><dfn>{/cal_cell_start}</dfn><br /> +<br /> + <dfn>{cal_cell_content}</dfn><var><a href="</var><kbd>{content}</kbd><var>"></var><kbd>{day}</kbd><var></a></var><dfn>{/cal_cell_content}</dfn><br /> + <dfn>{cal_cell_content_today}</dfn><var><div class="highlight"><a href="</var><kbd>{content}</kbd><var>"></var><kbd>{day}</kbd><var></a></div></var><dfn>{/cal_cell_content_today}</dfn><br /> +<br /> + <dfn>{cal_cell_no_content}</dfn><var></var><kbd>{day}</kbd><var></var><dfn>{/cal_cell_no_content}</dfn><br /> + <dfn>{cal_cell_no_content_today}</dfn><var><div class="highlight"></var><kbd>{day}</kbd><var></div></var><dfn>{/cal_cell_no_content_today}</dfn><br /> +<br /> + <dfn>{cal_cell_blank}</dfn><var>&nbsp;</var><dfn>{/cal_cell_blank}</dfn><br /> +<br /> + <dfn>{cal_cell_end}</dfn><var></td></var><dfn>{/cal_cell_end}</dfn><br /> + <dfn>{cal_row_end}</dfn><var></tr></var><dfn>{/cal_row_end}</dfn><br /> +<br /> + <dfn>{table_close}</dfn><var></table></var><dfn>{/table_close}</dfn><br /> +';<br /> +<br /> +$this->load->library('calendar', $prefs);<br /> +<br /> +echo $this->calendar->generate();</code> + + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="benchmark.html">Benchmarking Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="config.html">Config Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/config.html b/user_guide/libraries/config.html index 41a895665..8bc0a9059 100644 --- a/user_guide/libraries/config.html +++ b/user_guide/libraries/config.html @@ -1,181 +1,181 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Config Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Config Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>Config Class</h1>
-
-<p>The Config class provides a means to retrieve configuration preferences. These preferences can
-come from the default config file (<samp>application/config/config.php</samp>) or from your own custom config files.</p>
-
-<p class="important"><strong>Note:</strong> This class is initialized automatically by the system so there is no need to do it manually.</p>
-
-
-<h2>Anatomy of a Config File</h2>
-
-<p>By default, CodeIgniter has a one primary config file, located at <samp>application/config/config.php</samp>. If you open the file using
-your text editor you'll see that config items are stored in an array called <var>$config</var>.</p>
-
-<p>You can add your own config items to
-this file, or if you prefer to keep your configuration items separate (assuming you even need config items),
-simply create your own file and save it in <dfn>config</dfn> folder.</p>
-
-<p><strong>Note:</strong> If you do create your own config files use the same format as the primary one, storing your items in
-an array called <var>$config</var>. CodeIgniter will intelligently manage these files so there will be no conflict even though
-the array has the same name (assuming an array index is not named the same as another).</p>
-
-<h2>Loading a Config File</h2>
-
-<p><strong>Note:</strong> CodeIgniter automatically loads the primary config file (<samp>application/config/config.php</samp>),
-so you will only need to load a config file if you have created your own.</p>
-
-<p>There are two ways to load a config file:</p>
-
-<ol><li><strong>Manual Loading</strong>
-
-<p>To load one of your custom config files you will use the following function within the <a href="../general/controllers.html">controller</a> that needs it:</p>
-
-<code>$this->config->load('<var>filename</var>');</code>
-
-<p>Where <var>filename</var> is the name of your config file, without the .php file extension.</p>
-
-<p>If you need to load multiple config files normally they will be merged into one master config array. Name collisions can occur, however, if
-you have identically named array indexes in different config files. To avoid collisions you can set the second parameter to <kbd>TRUE</kbd>
-and each config file will be stored in an array index corresponding to the name of the config file. Example:</p>
-
-<code>
-// Stored in an array with this prototype: $this->config['blog_settings'] = $config<br />
-$this->config->load('<var>blog_settings</var>', <kbd>TRUE</kbd>);</code>
-
-<p>Please see the section entitled <dfn>Fetching Config Items</dfn> below to learn how to retrieve config items set this way.</p>
-
-<p>The third parameter allows you to suppress errors in the event that a config file does not exist:</p>
-
-<code>$this->config->load('<var>blog_settings</var>', <dfn>FALSE</dfn>, <kbd>TRUE</kbd>);</code>
-
-</li>
-<li><strong>Auto-loading</strong>
-
-<p>If you find that you need a particular config file globally, you can have it loaded automatically by the system. To do this,
-open the <strong>autoload.php</strong> file, located at <samp>application/config/autoload.php</samp>, and add your config file as
-indicated in the file.</p>
-</li>
-</ol>
-
-
-<h2>Fetching Config Items</h2>
-
-<p>To retrieve an item from your config file, use the following function:</p>
-
-<code>$this->config->item('<var>item name</var>');</code>
-
-<p>Where <var>item name</var> is the $config array index you want to retrieve. For example, to fetch your language choice you'll do this:</p>
-
-<code>$lang = $this->config->item('language');</code>
-
-<p>The function returns FALSE (boolean) if the item you are trying to fetch does not exist.</p>
-
-<p>If you are using the second parameter of the <kbd>$this->config->load</kbd> function in order to assign your config items to a specific index
-you can retrieve it by specifying the index name in the second parameter of the <kbd>$this->config->item()</kbd> function. Example:</p>
-
-<code>
-// Loads a config file named blog_settings.php and assigns it to an index named "blog_settings"<br />
-$this->config->load('<var>blog_settings</var>', <kbd>TRUE</kbd>);<br /><br />
-
-// Retrieve a config item named site_name contained within the blog_settings array<br />
-$site_name = $this->config->item('<dfn>site_name</dfn>', '<var>blog_settings</var>');<br /><br />
-
-// An alternate way to specify the same item:<br />
-$blog_config = $this->config->item('<var>blog_settings</var>');<br />
-$site_name = $blog_config['site_name'];</code>
-
-<h2>Setting a Config Item</h2>
-
-<p>If you would like to dynamically set a config item or change an existing one, you can so using:</p>
-
-<code>$this->config->set_item('<var>item_name</var>', '<var>item_value</var>');</code>
-
-<p>Where <var>item_name</var> is the $config array index you want to change, and <var>item_value</var> is its value.</p>
-
-
-<h2>Helper Functions</h2>
-
-<p>The config class has the following helper functions:</p>
-
-<h2>$this->config->site_url();</h2>
-<p>This function retrieves the URL to your site, along with the "index" value you've specified in the config file.</p>
-
-<h2>$this->config->system_url();</h2>
-<p>This function retrieves the URL to your <dfn>system folder</dfn>.</p>
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="calendar.html">Calendaring Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="../database/index.html">Database Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Config Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Config Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>Config Class</h1> + +<p>The Config class provides a means to retrieve configuration preferences. These preferences can +come from the default config file (<samp>application/config/config.php</samp>) or from your own custom config files.</p> + +<p class="important"><strong>Note:</strong> This class is initialized automatically by the system so there is no need to do it manually.</p> + + +<h2>Anatomy of a Config File</h2> + +<p>By default, CodeIgniter has a one primary config file, located at <samp>application/config/config.php</samp>. If you open the file using +your text editor you'll see that config items are stored in an array called <var>$config</var>.</p> + +<p>You can add your own config items to +this file, or if you prefer to keep your configuration items separate (assuming you even need config items), +simply create your own file and save it in <dfn>config</dfn> folder.</p> + +<p><strong>Note:</strong> If you do create your own config files use the same format as the primary one, storing your items in +an array called <var>$config</var>. CodeIgniter will intelligently manage these files so there will be no conflict even though +the array has the same name (assuming an array index is not named the same as another).</p> + +<h2>Loading a Config File</h2> + +<p><strong>Note:</strong> CodeIgniter automatically loads the primary config file (<samp>application/config/config.php</samp>), +so you will only need to load a config file if you have created your own.</p> + +<p>There are two ways to load a config file:</p> + +<ol><li><strong>Manual Loading</strong> + +<p>To load one of your custom config files you will use the following function within the <a href="../general/controllers.html">controller</a> that needs it:</p> + +<code>$this->config->load('<var>filename</var>');</code> + +<p>Where <var>filename</var> is the name of your config file, without the .php file extension.</p> + +<p>If you need to load multiple config files normally they will be merged into one master config array. Name collisions can occur, however, if +you have identically named array indexes in different config files. To avoid collisions you can set the second parameter to <kbd>TRUE</kbd> +and each config file will be stored in an array index corresponding to the name of the config file. Example:</p> + +<code> +// Stored in an array with this prototype: $this->config['blog_settings'] = $config<br /> +$this->config->load('<var>blog_settings</var>', <kbd>TRUE</kbd>);</code> + +<p>Please see the section entitled <dfn>Fetching Config Items</dfn> below to learn how to retrieve config items set this way.</p> + +<p>The third parameter allows you to suppress errors in the event that a config file does not exist:</p> + +<code>$this->config->load('<var>blog_settings</var>', <dfn>FALSE</dfn>, <kbd>TRUE</kbd>);</code> + +</li> +<li><strong>Auto-loading</strong> + +<p>If you find that you need a particular config file globally, you can have it loaded automatically by the system. To do this, +open the <strong>autoload.php</strong> file, located at <samp>application/config/autoload.php</samp>, and add your config file as +indicated in the file.</p> +</li> +</ol> + + +<h2>Fetching Config Items</h2> + +<p>To retrieve an item from your config file, use the following function:</p> + +<code>$this->config->item('<var>item name</var>');</code> + +<p>Where <var>item name</var> is the $config array index you want to retrieve. For example, to fetch your language choice you'll do this:</p> + +<code>$lang = $this->config->item('language');</code> + +<p>The function returns FALSE (boolean) if the item you are trying to fetch does not exist.</p> + +<p>If you are using the second parameter of the <kbd>$this->config->load</kbd> function in order to assign your config items to a specific index +you can retrieve it by specifying the index name in the second parameter of the <kbd>$this->config->item()</kbd> function. Example:</p> + +<code> +// Loads a config file named blog_settings.php and assigns it to an index named "blog_settings"<br /> +$this->config->load('<var>blog_settings</var>', <kbd>TRUE</kbd>);<br /><br /> + +// Retrieve a config item named site_name contained within the blog_settings array<br /> +$site_name = $this->config->item('<dfn>site_name</dfn>', '<var>blog_settings</var>');<br /><br /> + +// An alternate way to specify the same item:<br /> +$blog_config = $this->config->item('<var>blog_settings</var>');<br /> +$site_name = $blog_config['site_name'];</code> + +<h2>Setting a Config Item</h2> + +<p>If you would like to dynamically set a config item or change an existing one, you can so using:</p> + +<code>$this->config->set_item('<var>item_name</var>', '<var>item_value</var>');</code> + +<p>Where <var>item_name</var> is the $config array index you want to change, and <var>item_value</var> is its value.</p> + + +<h2>Helper Functions</h2> + +<p>The config class has the following helper functions:</p> + +<h2>$this->config->site_url();</h2> +<p>This function retrieves the URL to your site, along with the "index" value you've specified in the config file.</p> + +<h2>$this->config->system_url();</h2> +<p>This function retrieves the URL to your <dfn>system folder</dfn>.</p> + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="calendar.html">Calendaring Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="../database/index.html">Database Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/email.html b/user_guide/libraries/email.html index 64f56acac..22643ef15 100644 --- a/user_guide/libraries/email.html +++ b/user_guide/libraries/email.html @@ -1,307 +1,307 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Email Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Email Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>Email Class</h1>
-
-<p>CodeIgniter's robust Email Class supports the following features:</p>
-
-
-<ul>
-<li>Multiple Protocols: Mail, Sendmail, and SMTP</li>
-<li>Multiple recipients</li>
-<li>CC and BCCs</li>
-<li>HTML or Plaintext email</li>
-<li>Attachments</li>
-<li>Word wrapping</li>
-<li>Priorities</li>
-<li>BCC Batch Mode, enabling large email lists to be broken into small BCC batches.</li>
-<li>Email Debugging tools</li>
-</ul>
-
-
-<h2>Sending Email</h2>
-
-<p>Sending email is not only simple, but you can configure it on the fly or set your preferences in a config file.</p>
-
-<p>Here is a basic example demonstrating how you might send email. Note: This example assumes you are sending the email from one of your
-<a href="../general/controllers.html">controllers</a>.</p>
-
-<code>$this->load->library('email');<br />
-<br />
-$this->email->from('your@example.com', 'Your Name');<br />
-$this->email->to('someone@example.com'); <br />
-$this->email->cc('another@another-example.com'); <br />
-$this->email->bcc('them@their-example.com'); <br />
-<br />
-$this->email->subject('Email Test');<br />
-$this->email->message('Testing the email class.'); <br />
-<br />
-$this->email->send();<br />
-<br />
-echo $this->email->print_debugger();</code>
-
-
-
-
-<h2>Setting Email Preferences</h2>
-
-<p>There are 17 different preferences available to tailor how your email messages are sent. You can either set them manually
-as described here, or automatically via preferences stored in your config file, described below:</p>
-
-<p>Preferences are set by passing an array of preference values to the email <dfn>initialize</dfn> function. Here is an example of how you might set some preferences:</p>
-
-<code>$config['protocol'] = 'sendmail';<br />
-$config['mailpath'] = '/usr/sbin/sendmail';<br />
-$config['charset'] = 'iso-8859-1';<br />
-$config['wordwrap'] = TRUE;<br />
-<br />
-$this->email->initialize($config);</code>
-
-<p><strong>Note:</strong> Most of the preferences have default values that will be used if you do not set them.</p
-
-><h3>Setting Email Preferences in a Config File</h3>
-
-<p>If you prefer not to set preferences using the above method, you can instead put them into a config file.
-Simply create a new file called the <var>email.php</var>, add the <var>$config</var>
-array in that file. Then save the file at <var>config/email.php</var> and it will be used automatically. You
-will NOT need to use the <dfn>$this->email->initialize()</dfn> function if you save your preferences in a config file.</p>
-
-
-
-
-<h2>Email Preferences</h2>
-
-<p>The following is a list of all the preferences that can be set when sending email.</p>
-
-
-<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
-<tr>
-<th>Preference</th>
-<th>Default Value</th>
-<th>Options</th>
-<th>Description</th>
-</tr><tr>
-<td class="td"><strong>useragent</strong></td><td class="td">CodeIgniter</td><td class="td">None</td><td class="td">The "user agent".</td>
-</tr><tr>
-<td class="td"><strong>protocol</strong></td><td class="td">mail</td><td class="td">mail, sendmail, or smtp</td><td class="td">The mail sending protocol.</td>
-</tr><tr>
-<td class="td"><strong>mailpath</strong></td><td class="td">/usr/sbin/sendmail</td><td class="td">None</td><td class="td">The server path to Sendmail.</td>
-</tr><tr>
-<td class="td"><strong>smtp_host</strong></td><td class="td">No Default</td><td class="td">None</td><td class="td">SMTP Server Address.</td>
-</tr><tr>
-<td class="td"><strong>smtp_user</strong></td><td class="td">No Default</td><td class="td">None</td><td class="td">SMTP Username.</td>
-</tr><tr>
-<td class="td"><strong>smtp_pass</strong></td><td class="td">No Default</td><td class="td">None</td><td class="td">SMTP Password.</td>
-</tr><tr>
-<td class="td"><strong>smtp_port</strong></td><td class="td">25</td><td class="td">None</td><td class="td">SMTP Port.</td>
-</tr><tr>
-<td class="td"><strong>smtp_timeout</strong></td><td class="td">5</td><td class="td">None</td><td class="td">SMTP Timeout (in seconds).</td>
-</tr><tr>
-<td class="td"><strong>wordwrap</strong></td><td class="td">TRUE</td><td class="td">TRUE or FALSE (boolean)</td><td class="td">Enable word-wrap.</td>
-</tr><tr>
-<td class="td"><strong>wrapchars</strong></td><td class="td">76</td><td class="td"> </td><td class="td">Character count to wrap at.</td>
-</tr><tr>
-<td class="td"><strong>mailtype</strong></td><td class="td">text</td><td class="td">text or html</td><td class="td">Type of mail. If you send HTML email you must send it as a complete web page. Make sure you don't have any relative links or relative image paths otherwise they will not work.</td>
-</tr><tr>
-<td class="td"><strong>charset</strong></td><td class="td">utf-8</td><td class="td"></td><td class="td">Character set (utf-8, iso-8859-1, etc.).</td>
-</tr><tr>
-<td class="td"><strong>validate</strong></td><td class="td">FALSE</td><td class="td">TRUE or FALSE (boolean)</td><td class="td">Whether to validate the email address.</td>
-</tr><tr>
-<td class="td"><strong>priority</strong></td><td class="td">3</td><td class="td">1, 2, 3, 4, 5</td><td class="td">Email Priority. 1 = highest. 5 = lowest. 3 = normal.</td>
-</tr>
-<tr>
- <td class="td"><strong>crlf</strong></td>
- <td class="td">\n</td>
- <td class="td">"\r\n" or "\n" or "\r"</td>
- <td class="td">Newline character. (Use "\r\n" to comply with RFC 822).</td>
-</tr>
-<tr>
-<td class="td"><strong>newline</strong></td><td class="td">\n</td>
-<td class="td">"\r\n" or "\n" or "\r"</td><td class="td">Newline character. (Use "\r\n" to comply with RFC 822).</td>
-</tr><tr>
-<td class="td"><strong>bcc_batch_mode</strong></td><td class="td">FALSE</td><td class="td">TRUE or FALSE (boolean)</td><td class="td">Enable BCC Batch Mode.</td>
-</tr><tr>
-<td class="td"><strong>bcc_batch_size</strong></td><td class="td">200</td><td class="td">None</td><td class="td">Number of emails in each BCC batch.</td>
-</tr>
-</table>
-
-
-<h2>Email Function Reference</h2>
-
-<h3>$this->email->from()</h3>
-<p>Sets the email address and name of the person sending the email:</p>
-<code>$this->email->from('<var>you@example.com</var>', '<var>Your Name</var>');</code>
-
-<h3>$this->email->reply_to()</h3>
-<p>Sets the reply-to address. If the information is not provided the information in the "from" function is used. Example:</p>
-<code>$this->email->reply_to('<var>you@example.com</var>', '<var>Your Name</var>');</code>
-
-
-<h3>$this->email->to()</h3>
-<p>Sets the email address(s) of the recipient(s). Can be a single email, a comma-delimited list or an array:</p>
-
-<code>$this->email->to('<var>someone@example.com</var>');</code>
-<code>$this->email->to('<var>one@example.com</var>, <var>two@example.com</var>, <var>three@example.com</var>');</code>
-
-<code>$list = array('<var>one@example.com</var>', '<var>two@example.com</var>', '<var>three@example.com</var>');<br />
-<br />
-$this->email->to(<var>$list</var>);</code>
-
-<h3>$this->email->cc()</h3>
-<p>Sets the CC email address(s). Just like the "to", can be a single email, a comma-delimited list or an array.</p>
-
-<h3>$this->email->bcc()</h3>
-<p>Sets the BCC email address(s). Just like the "to", can be a single email, a comma-delimited list or an array.</p>
-
-
-<h3>$this->email->subject()</h3>
-<p>Sets the email subject:</p>
-<code>$this->email->subject('<var>This is my subject</var>');</code>
-
-<h3>$this->email->message()</h3>
-<p>Sets the email message body:</p>
-<code>$this->email->message('<var>This is my message</var>');</code>
-
-<h3>$this->email->set_alt_message()</h3>
-<p>Sets the alternative email message body:</p>
-<code>$this->email->set_alt_message('<var>This is the alternative message</var>');</code>
-
-<p>This is an optional message string which can be used if you send HTML formatted email. It lets you specify an alternative
-message with no HTML formatting which is added to the header string for people who do not accept HTML email.
-If you do not set your own message CodeIgniter will extract the message from your HTML email and strip the tags.</p>
-
-
-
-<h3>$this->email->clear()</h3>
-<p>Initializes all the email variables to an empty state. This function is intended for use if you run the email sending function
-in a loop, permitting the data to be reset between cycles.</p>
-<code>foreach ($list as $name => $address)<br />
-{<br />
- $this->email->clear();<br /><br />
-
- $this->email->to($address);<br />
- $this->email->from('your@example.com');<br />
- $this->email->subject('Here is your info '.$name);<br />
- $this->email->message('Hi '.$name.' Here is the info you requested.');<br />
- $this->email->send();<br />
-}</code>
-
-<p>If you set the parameter to TRUE any attachments will be cleared as well:</p>
-
-<code>$this->email->clear(TRUE);</code>
-
-
-<h3>$this->email->send()</h3>
-<p>The Email sending function. Returns boolean TRUE or FALSE based on success or failure, enabling it to be used
-conditionally:</p>
-
-<code>if ( ! $this->email->send())<br />
-{<br />
- // Generate error<br />
-}</code>
-
-
-<h3>$this->email->attach()</h3>
-<p>Enables you to send an attachment. Put the file path/name in the first parameter. Note: Use a file path, not a URL.
-For multiple attachments use the function multiple times. For example:</p>
-
-<code>$this->email->attach('/path/to/photo1.jpg');<br />
-$this->email->attach('/path/to/photo2.jpg');<br />
-$this->email->attach('/path/to/photo3.jpg');<br />
-<br />
-$this->email->send();</code>
-
-
-<h3>$this->email->print_debugger()</h3>
-<p>Returns a string containing any server messages, the email headers, and the email messsage. Useful for debugging.</p>
-
-
-<h2>Overriding Word Wrapping</h2>
-
-<p>If you have word wrapping enabled (recommended to comply with RFC 822) and you have a very long link in your email it can
-get wrapped too, causing it to become un-clickable by the person receiving it. CodeIgniter lets you manually override
-word wrapping within part of your message like this:</p>
-
-<code>The text of your email that<br />
-gets wrapped normally.<br />
-<br />
-<var>{unwrap}</var>http://example.com/a_long_link_that_should_not_be_wrapped.html<var>{/unwrap}</var><br />
-<br />
-More text that will be<br />
-wrapped normally.</code>
-
-<p>Place the item you do not want word-wrapped between: <var>{unwrap}</var> <var>{/unwrap}</var></p>
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="database/index.html">Database Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="encryption.html">Encryption Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Email Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Email Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>Email Class</h1> + +<p>CodeIgniter's robust Email Class supports the following features:</p> + + +<ul> +<li>Multiple Protocols: Mail, Sendmail, and SMTP</li> +<li>Multiple recipients</li> +<li>CC and BCCs</li> +<li>HTML or Plaintext email</li> +<li>Attachments</li> +<li>Word wrapping</li> +<li>Priorities</li> +<li>BCC Batch Mode, enabling large email lists to be broken into small BCC batches.</li> +<li>Email Debugging tools</li> +</ul> + + +<h2>Sending Email</h2> + +<p>Sending email is not only simple, but you can configure it on the fly or set your preferences in a config file.</p> + +<p>Here is a basic example demonstrating how you might send email. Note: This example assumes you are sending the email from one of your +<a href="../general/controllers.html">controllers</a>.</p> + +<code>$this->load->library('email');<br /> +<br /> +$this->email->from('your@example.com', 'Your Name');<br /> +$this->email->to('someone@example.com'); <br /> +$this->email->cc('another@another-example.com'); <br /> +$this->email->bcc('them@their-example.com'); <br /> +<br /> +$this->email->subject('Email Test');<br /> +$this->email->message('Testing the email class.'); <br /> +<br /> +$this->email->send();<br /> +<br /> +echo $this->email->print_debugger();</code> + + + + +<h2>Setting Email Preferences</h2> + +<p>There are 17 different preferences available to tailor how your email messages are sent. You can either set them manually +as described here, or automatically via preferences stored in your config file, described below:</p> + +<p>Preferences are set by passing an array of preference values to the email <dfn>initialize</dfn> function. Here is an example of how you might set some preferences:</p> + +<code>$config['protocol'] = 'sendmail';<br /> +$config['mailpath'] = '/usr/sbin/sendmail';<br /> +$config['charset'] = 'iso-8859-1';<br /> +$config['wordwrap'] = TRUE;<br /> +<br /> +$this->email->initialize($config);</code> + +<p><strong>Note:</strong> Most of the preferences have default values that will be used if you do not set them.</p + +><h3>Setting Email Preferences in a Config File</h3> + +<p>If you prefer not to set preferences using the above method, you can instead put them into a config file. +Simply create a new file called the <var>email.php</var>, add the <var>$config</var> +array in that file. Then save the file at <var>config/email.php</var> and it will be used automatically. You +will NOT need to use the <dfn>$this->email->initialize()</dfn> function if you save your preferences in a config file.</p> + + + + +<h2>Email Preferences</h2> + +<p>The following is a list of all the preferences that can be set when sending email.</p> + + +<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder"> +<tr> +<th>Preference</th> +<th>Default Value</th> +<th>Options</th> +<th>Description</th> +</tr><tr> +<td class="td"><strong>useragent</strong></td><td class="td">CodeIgniter</td><td class="td">None</td><td class="td">The "user agent".</td> +</tr><tr> +<td class="td"><strong>protocol</strong></td><td class="td">mail</td><td class="td">mail, sendmail, or smtp</td><td class="td">The mail sending protocol.</td> +</tr><tr> +<td class="td"><strong>mailpath</strong></td><td class="td">/usr/sbin/sendmail</td><td class="td">None</td><td class="td">The server path to Sendmail.</td> +</tr><tr> +<td class="td"><strong>smtp_host</strong></td><td class="td">No Default</td><td class="td">None</td><td class="td">SMTP Server Address.</td> +</tr><tr> +<td class="td"><strong>smtp_user</strong></td><td class="td">No Default</td><td class="td">None</td><td class="td">SMTP Username.</td> +</tr><tr> +<td class="td"><strong>smtp_pass</strong></td><td class="td">No Default</td><td class="td">None</td><td class="td">SMTP Password.</td> +</tr><tr> +<td class="td"><strong>smtp_port</strong></td><td class="td">25</td><td class="td">None</td><td class="td">SMTP Port.</td> +</tr><tr> +<td class="td"><strong>smtp_timeout</strong></td><td class="td">5</td><td class="td">None</td><td class="td">SMTP Timeout (in seconds).</td> +</tr><tr> +<td class="td"><strong>wordwrap</strong></td><td class="td">TRUE</td><td class="td">TRUE or FALSE (boolean)</td><td class="td">Enable word-wrap.</td> +</tr><tr> +<td class="td"><strong>wrapchars</strong></td><td class="td">76</td><td class="td"> </td><td class="td">Character count to wrap at.</td> +</tr><tr> +<td class="td"><strong>mailtype</strong></td><td class="td">text</td><td class="td">text or html</td><td class="td">Type of mail. If you send HTML email you must send it as a complete web page. Make sure you don't have any relative links or relative image paths otherwise they will not work.</td> +</tr><tr> +<td class="td"><strong>charset</strong></td><td class="td">utf-8</td><td class="td"></td><td class="td">Character set (utf-8, iso-8859-1, etc.).</td> +</tr><tr> +<td class="td"><strong>validate</strong></td><td class="td">FALSE</td><td class="td">TRUE or FALSE (boolean)</td><td class="td">Whether to validate the email address.</td> +</tr><tr> +<td class="td"><strong>priority</strong></td><td class="td">3</td><td class="td">1, 2, 3, 4, 5</td><td class="td">Email Priority. 1 = highest. 5 = lowest. 3 = normal.</td> +</tr> +<tr> + <td class="td"><strong>crlf</strong></td> + <td class="td">\n</td> + <td class="td">"\r\n" or "\n" or "\r"</td> + <td class="td">Newline character. (Use "\r\n" to comply with RFC 822).</td> +</tr> +<tr> +<td class="td"><strong>newline</strong></td><td class="td">\n</td> +<td class="td">"\r\n" or "\n" or "\r"</td><td class="td">Newline character. (Use "\r\n" to comply with RFC 822).</td> +</tr><tr> +<td class="td"><strong>bcc_batch_mode</strong></td><td class="td">FALSE</td><td class="td">TRUE or FALSE (boolean)</td><td class="td">Enable BCC Batch Mode.</td> +</tr><tr> +<td class="td"><strong>bcc_batch_size</strong></td><td class="td">200</td><td class="td">None</td><td class="td">Number of emails in each BCC batch.</td> +</tr> +</table> + + +<h2>Email Function Reference</h2> + +<h3>$this->email->from()</h3> +<p>Sets the email address and name of the person sending the email:</p> +<code>$this->email->from('<var>you@example.com</var>', '<var>Your Name</var>');</code> + +<h3>$this->email->reply_to()</h3> +<p>Sets the reply-to address. If the information is not provided the information in the "from" function is used. Example:</p> +<code>$this->email->reply_to('<var>you@example.com</var>', '<var>Your Name</var>');</code> + + +<h3>$this->email->to()</h3> +<p>Sets the email address(s) of the recipient(s). Can be a single email, a comma-delimited list or an array:</p> + +<code>$this->email->to('<var>someone@example.com</var>');</code> +<code>$this->email->to('<var>one@example.com</var>, <var>two@example.com</var>, <var>three@example.com</var>');</code> + +<code>$list = array('<var>one@example.com</var>', '<var>two@example.com</var>', '<var>three@example.com</var>');<br /> +<br /> +$this->email->to(<var>$list</var>);</code> + +<h3>$this->email->cc()</h3> +<p>Sets the CC email address(s). Just like the "to", can be a single email, a comma-delimited list or an array.</p> + +<h3>$this->email->bcc()</h3> +<p>Sets the BCC email address(s). Just like the "to", can be a single email, a comma-delimited list or an array.</p> + + +<h3>$this->email->subject()</h3> +<p>Sets the email subject:</p> +<code>$this->email->subject('<var>This is my subject</var>');</code> + +<h3>$this->email->message()</h3> +<p>Sets the email message body:</p> +<code>$this->email->message('<var>This is my message</var>');</code> + +<h3>$this->email->set_alt_message()</h3> +<p>Sets the alternative email message body:</p> +<code>$this->email->set_alt_message('<var>This is the alternative message</var>');</code> + +<p>This is an optional message string which can be used if you send HTML formatted email. It lets you specify an alternative +message with no HTML formatting which is added to the header string for people who do not accept HTML email. +If you do not set your own message CodeIgniter will extract the message from your HTML email and strip the tags.</p> + + + +<h3>$this->email->clear()</h3> +<p>Initializes all the email variables to an empty state. This function is intended for use if you run the email sending function +in a loop, permitting the data to be reset between cycles.</p> +<code>foreach ($list as $name => $address)<br /> +{<br /> + $this->email->clear();<br /><br /> + + $this->email->to($address);<br /> + $this->email->from('your@example.com');<br /> + $this->email->subject('Here is your info '.$name);<br /> + $this->email->message('Hi '.$name.' Here is the info you requested.');<br /> + $this->email->send();<br /> +}</code> + +<p>If you set the parameter to TRUE any attachments will be cleared as well:</p> + +<code>$this->email->clear(TRUE);</code> + + +<h3>$this->email->send()</h3> +<p>The Email sending function. Returns boolean TRUE or FALSE based on success or failure, enabling it to be used +conditionally:</p> + +<code>if ( ! $this->email->send())<br /> +{<br /> + // Generate error<br /> +}</code> + + +<h3>$this->email->attach()</h3> +<p>Enables you to send an attachment. Put the file path/name in the first parameter. Note: Use a file path, not a URL. +For multiple attachments use the function multiple times. For example:</p> + +<code>$this->email->attach('/path/to/photo1.jpg');<br /> +$this->email->attach('/path/to/photo2.jpg');<br /> +$this->email->attach('/path/to/photo3.jpg');<br /> +<br /> +$this->email->send();</code> + + +<h3>$this->email->print_debugger()</h3> +<p>Returns a string containing any server messages, the email headers, and the email messsage. Useful for debugging.</p> + + +<h2>Overriding Word Wrapping</h2> + +<p>If you have word wrapping enabled (recommended to comply with RFC 822) and you have a very long link in your email it can +get wrapped too, causing it to become un-clickable by the person receiving it. CodeIgniter lets you manually override +word wrapping within part of your message like this:</p> + +<code>The text of your email that<br /> +gets wrapped normally.<br /> +<br /> +<var>{unwrap}</var>http://example.com/a_long_link_that_should_not_be_wrapped.html<var>{/unwrap}</var><br /> +<br /> +More text that will be<br /> +wrapped normally.</code> + +<p>Place the item you do not want word-wrapped between: <var>{unwrap}</var> <var>{/unwrap}</var></p> + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="database/index.html">Database Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="encryption.html">Encryption Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/encryption.html b/user_guide/libraries/encryption.html index 092dad2ac..a0733ab19 100644 --- a/user_guide/libraries/encryption.html +++ b/user_guide/libraries/encryption.html @@ -1,182 +1,182 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Encryption Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Encryption Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>Encryption Class</h1>
-
-<p>The Encryption Class provides two-way data encryption. It uses a scheme that pre-compiles
-the message using a randomly hashed bitwise XOR encoding scheme, which is then encrypted using
-the Mcrypt library. If Mcrypt is not available on your server the encoded message will
-still provide a reasonable degree of security for encrypted sessions or other such "light" purposes.
-If Mcrypt is available, you'll effectively end up with a double-encrypted message string, which should
-provide a very high degree of security.</p>
-
-
-<h2>Setting your Key</h2>
-
-<p>A <em>key</em> is a piece of information that controls the cryptographic process and permits an encrypted string to be decoded.
-In fact, the key you chose will provide the <strong>only</strong> means to decode data that was encrypted with that key,
-so not only must you choose the key carefully, you must never change it if you intend use it for persistent data.</p>
-
-<p>It goes without saying that you should guard your key carefully.
-Should someone gain access to your key, the data will be easily decoded. If your server is not totally under your control
-it's impossible to ensure key security so you may want to think carefully before using it for anything
-that requires high security, like storing credit card numbers.</p>
-
-<p>To take maximum advantage of the encryption algorithm, your key should be 32 characters in length (128 bits).
-The key should be as random a string as you can concoct, with numbers and uppercase and lowercase letters.
-Your key should <strong>not</strong> be a simple text string. In order to be cryptographically secure it
-needs to be as random as possible.</p>
-
-<p>Your key can be either stored in your <dfn>application/config/config.php</dfn>, or you can design your own
-storage mechanism and pass the key dynamically when encoding/decoding.</p>
-
-<p>To save your key to your <dfn>application/config/config.php</dfn>, open the file and set:</p>
-<code>$config['encryption_key'] = "YOUR KEY";</code>
-
-
-<h2>Message Length</h2>
-
-<p>It's important for you to know that the encoded messages the encryption function generates will be approximately 2.6 times longer than the original
-message. For example, if you encrypt the string "my super secret data", which is 21 characters in length, you'll end up
-with an encoded string that is roughly 55 characters (we say "roughly" because the encoded string length increments in
-64 bit clusters, so it's not exactly linear). Keep this information in mind when selecting your data storage mechanism. Cookies,
-for example, can only hold 4K of information.</p>
-
-
-<h2>Initializing the Class</h2>
-
-<p>Like most other classes in CodeIgniter, the Encryption class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
-
-<code>$this->load->library('encrypt');</code>
-<p>Once loaded, the Encrypt library object will be available using: <dfn>$this->encrypt</dfn></p>
-
-
-<h2>$this->encrypt->encode()</h2>
-
-<p>Performs the data encryption and returns it as a string. Example:</p>
-<code>
-$msg = 'My secret message';<br />
-<br />
-$encrypted_string = $this->encrypt->encode($msg);</code>
-
-<p>You can optionally pass your encryption key via the second parameter if you don't want to use the one in your config file:</p>
-
-<code>
-$msg = 'My secret message';<br />
-$key = 'super-secret-key';<br />
-<br />
-$encrypted_string = $this->encrypt->encode($msg, $key);</code>
-
-
-<h2>$this->encrypt->decode()</h2>
-
-<p>Decrypts an encoded string. Example:</p>
-
-<code>
-$encrypted_string = 'APANtByIGI1BpVXZTJgcsAG8GZl8pdwwa84';<br />
-<br />
-$plaintext_string = $this->encrypt->decode($encrypted_string);</code>
-
-
-<h2>$this->encrypt->set_cipher();</h2>
-
-<p>Permits you to set an Mcrypt cipher. By default it uses <samp>MCRYPT_RIJNDAEL_256</samp>. Example:</p>
-<code>$this->encrypt->set_cipher(MCRYPT_BLOWFISH);</code>
-<p>Please visit php.net for a list of <a href="http://php.net/mcrypt">available ciphers</a>.</p>
-
-<p>If you'd like to manually test whether your server supports Mcrypt you can use:</p>
-<code>echo ( ! function_exists('mcrypt_encrypt')) ? 'Nope' : 'Yup';</code>
-
-
-<h2>$this->encrypt->set_mode();</h2>
-
-<p>Permits you to set an Mcrypt mode. By default it uses <samp>MCRYPT_MODE_ECB</samp>. Example:</p>
-<code>$this->encrypt->set_mode(MCRYPT_MODE_CFB);</code>
-<p>Please visit php.net for a list of <a href="http://php.net/mcrypt">available modes</a>.</p>
-
-
-<h2>$this->encrypt->sha1();</h2>
-<p>SHA1 encoding function. Provide a string and it will return a 160 bit one way hash. Note: SHA1, just like MD5 is non-decodable. Example:</p>
-<code>$hash = $this->encrypt->sha1('Some string');</code>
-
-<p>Many PHP installations have SHA1 support by default so if all you need is to encode a hash it's simpler to use the native
-function:</p>
-
-<code>$hash = sha1('Some string');</code>
-
-<p>If your server does not support SHA1 you can use the provided function.</p>
-
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="email.html">Email Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="file_uploading.html">File Uploading Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Encryption Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Encryption Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>Encryption Class</h1> + +<p>The Encryption Class provides two-way data encryption. It uses a scheme that pre-compiles +the message using a randomly hashed bitwise XOR encoding scheme, which is then encrypted using +the Mcrypt library. If Mcrypt is not available on your server the encoded message will +still provide a reasonable degree of security for encrypted sessions or other such "light" purposes. +If Mcrypt is available, you'll effectively end up with a double-encrypted message string, which should +provide a very high degree of security.</p> + + +<h2>Setting your Key</h2> + +<p>A <em>key</em> is a piece of information that controls the cryptographic process and permits an encrypted string to be decoded. +In fact, the key you chose will provide the <strong>only</strong> means to decode data that was encrypted with that key, +so not only must you choose the key carefully, you must never change it if you intend use it for persistent data.</p> + +<p>It goes without saying that you should guard your key carefully. +Should someone gain access to your key, the data will be easily decoded. If your server is not totally under your control +it's impossible to ensure key security so you may want to think carefully before using it for anything +that requires high security, like storing credit card numbers.</p> + +<p>To take maximum advantage of the encryption algorithm, your key should be 32 characters in length (128 bits). +The key should be as random a string as you can concoct, with numbers and uppercase and lowercase letters. +Your key should <strong>not</strong> be a simple text string. In order to be cryptographically secure it +needs to be as random as possible.</p> + +<p>Your key can be either stored in your <dfn>application/config/config.php</dfn>, or you can design your own +storage mechanism and pass the key dynamically when encoding/decoding.</p> + +<p>To save your key to your <dfn>application/config/config.php</dfn>, open the file and set:</p> +<code>$config['encryption_key'] = "YOUR KEY";</code> + + +<h2>Message Length</h2> + +<p>It's important for you to know that the encoded messages the encryption function generates will be approximately 2.6 times longer than the original +message. For example, if you encrypt the string "my super secret data", which is 21 characters in length, you'll end up +with an encoded string that is roughly 55 characters (we say "roughly" because the encoded string length increments in +64 bit clusters, so it's not exactly linear). Keep this information in mind when selecting your data storage mechanism. Cookies, +for example, can only hold 4K of information.</p> + + +<h2>Initializing the Class</h2> + +<p>Like most other classes in CodeIgniter, the Encryption class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p> + +<code>$this->load->library('encrypt');</code> +<p>Once loaded, the Encrypt library object will be available using: <dfn>$this->encrypt</dfn></p> + + +<h2>$this->encrypt->encode()</h2> + +<p>Performs the data encryption and returns it as a string. Example:</p> +<code> +$msg = 'My secret message';<br /> +<br /> +$encrypted_string = $this->encrypt->encode($msg);</code> + +<p>You can optionally pass your encryption key via the second parameter if you don't want to use the one in your config file:</p> + +<code> +$msg = 'My secret message';<br /> +$key = 'super-secret-key';<br /> +<br /> +$encrypted_string = $this->encrypt->encode($msg, $key);</code> + + +<h2>$this->encrypt->decode()</h2> + +<p>Decrypts an encoded string. Example:</p> + +<code> +$encrypted_string = 'APANtByIGI1BpVXZTJgcsAG8GZl8pdwwa84';<br /> +<br /> +$plaintext_string = $this->encrypt->decode($encrypted_string);</code> + + +<h2>$this->encrypt->set_cipher();</h2> + +<p>Permits you to set an Mcrypt cipher. By default it uses <samp>MCRYPT_RIJNDAEL_256</samp>. Example:</p> +<code>$this->encrypt->set_cipher(MCRYPT_BLOWFISH);</code> +<p>Please visit php.net for a list of <a href="http://php.net/mcrypt">available ciphers</a>.</p> + +<p>If you'd like to manually test whether your server supports Mcrypt you can use:</p> +<code>echo ( ! function_exists('mcrypt_encrypt')) ? 'Nope' : 'Yup';</code> + + +<h2>$this->encrypt->set_mode();</h2> + +<p>Permits you to set an Mcrypt mode. By default it uses <samp>MCRYPT_MODE_ECB</samp>. Example:</p> +<code>$this->encrypt->set_mode(MCRYPT_MODE_CFB);</code> +<p>Please visit php.net for a list of <a href="http://php.net/mcrypt">available modes</a>.</p> + + +<h2>$this->encrypt->sha1();</h2> +<p>SHA1 encoding function. Provide a string and it will return a 160 bit one way hash. Note: SHA1, just like MD5 is non-decodable. Example:</p> +<code>$hash = $this->encrypt->sha1('Some string');</code> + +<p>Many PHP installations have SHA1 support by default so if all you need is to encode a hash it's simpler to use the native +function:</p> + +<code>$hash = sha1('Some string');</code> + +<p>If your server does not support SHA1 you can use the provided function.</p> + + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="email.html">Email Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="file_uploading.html">File Uploading Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/file_uploading.html b/user_guide/libraries/file_uploading.html index fb9769758..a840c1ec3 100644 --- a/user_guide/libraries/file_uploading.html +++ b/user_guide/libraries/file_uploading.html @@ -1,438 +1,438 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>File Uploading Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-File Uploading Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>File Uploading Class</h1>
-
-<p>CodeIgniter's File Uploading Class permits files to be uploaded. You can set various
-preferences, restricting the type and size of the files.</p>
-
-
-<h2>The Process</h2>
-
-<p>Uploading a file involves the following general process:</p>
-
-
-<ul>
-<li>An upload form is displayed, allowing a user to select a file and upload it.</li>
-<li>When the form is submitted, the file is uploaded to the destination you specify.</li>
-<li>Along the way, the file is validated to make sure it is allowed to be uploaded based on the preferences you set.</li>
-<li>Once uploaded, the user will be shown a success message.</li>
-</ul>
-
-<p>To demonstrate this process here is brief tutorial. Afterward you'll find reference information.</p>
-
-<h2>Creating the Upload Form</h2>
-
-
-
-<p>Using a text editor, create a form called <dfn>upload_form.php</dfn>. In it, place this code and save it to your <samp>applications/views/</samp>
-folder:</p>
-
-
-<textarea class="textarea" style="width:100%" cols="50" rows="23">
-<html>
-<head>
-<title>Upload Form</title>
-</head>
-<body>
-
-<?php echo $error;?>
-
-<?php echo form_open_multipart('upload/do_upload');?>
-
-<input type="file" name="userfile" size="20" />
-
-<br /><br />
-
-<input type="submit" value="upload" />
-
-</form>
-
-</body>
-</html></textarea>
-
-<p>You'll notice we are using a form helper to create the opening form tag. File uploads require a multipart form, so the helper
-creates the proper syntax for you. You'll also notice we have an $error variable. This is so we can show error messages in the event
-the user does something wrong.</p>
-
-
-<h2>The Success Page</h2>
-
-<p>Using a text editor, create a form called <dfn>upload_success.php</dfn>.
-In it, place this code and save it to your <samp>applications/views/</samp> folder:</p>
-
-<textarea class="textarea" style="width:100%" cols="50" rows="20"><html>
-<head>
-<title>Upload Form</title>
-</head>
-<body>
-
-<h3>Your file was successfully uploaded!</h3>
-
-<ul>
-<?php foreach($upload_data as $item => $value):?>
-<li><?php echo $item;?>: <?php echo $value;?></li>
-<?php endforeach; ?>
-</ul>
-
-<p><?php echo anchor('upload', 'Upload Another File!'); ?></p>
-
-</body>
-</html></textarea>
-
-
-<h2>The Controller</h2>
-
-<p>Using a text editor, create a controller called <dfn>upload.php</dfn>. In it, place this code and save it to your <samp>applications/controllers/</samp>
-folder:</p>
-
-
-<textarea class="textarea" style="width:100%" cols="50" rows="43"><?php
-
-class Upload extends Controller {
-
- function Upload()
- {
- parent::Controller();
- $this->load->helper(array('form', 'url'));
- }
-
- function index()
- {
- $this->load->view('upload_form', array('error' => ' ' ));
- }
-
- function do_upload()
- {
- $config['upload_path'] = './uploads/';
- $config['allowed_types'] = 'gif|jpg|png';
- $config['max_size'] = '100';
- $config['max_width'] = '1024';
- $config['max_height'] = '768';
-
- $this->load->library('upload', $config);
-
- if ( ! $this->upload->do_upload())
- {
- $error = array('error' => $this->upload->display_errors());
-
- $this->load->view('upload_form', $error);
- }
- else
- {
- $data = array('upload_data' => $this->upload->data());
-
- $this->load->view('upload_success', $data);
- }
- }
-}
-?></textarea>
-
-
-<h2>The Upload Folder</h2>
-
-<p>You'll need a destination folder for your uploaded images. Create a folder at the root of your CodeIgniter installation called
-<dfn>uploads</dfn> and set its file permissions to 777.</p>
-
-
-<h2>Try it!</h2>
-
-<p>To try your form, visit your site using a URL similar to this one:</p>
-
-<code>example.com/index.php/<var>upload</var>/</code>
-
-<p>You should see an upload form. Try uploading an image file (either a jpg, gif, or png). If the path in your
-controller is correct it should work.</p>
-
-
-<p> </p>
-
-<h1>Reference Guide</h1>
-
-
-<h2>Initializing the Upload Class</h2>
-
-<p>Like most other classes in CodeIgniter, the Upload class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
-
-<code>$this->load->library('upload');</code>
-<p>Once the Upload class is loaded, the object will be available using: <dfn>$this->upload</dfn></p>
-
-
-<h2>Setting Preferences</h2>
-
-<p>Similar to other libraries, you'll control what is allowed to be upload based on your preferences. In the controller you
-built above you set the following preferences:</p>
-
-<code>$config['upload_path'] = './uploads/';<br />
-$config['allowed_types'] = 'gif|jpg|png';<br />
-$config['max_size'] = '100';<br />
-$config['max_width'] = '1024';<br />
-$config['max_height'] = '768';<br />
-<br />
-$this->load->library('upload', $config);<br /><br />
-
-// Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class:<br />
-$this->upload->initialize($config);</code>
-
-<p>The above preferences should be fairly self-explanatory. Below is a table describing all available preferences.</p>
-
-
-<h2>Preferences</h2>
-
-<p>The following preferences are available. The default value indicates what will be used if you do not specify that preference.</p>
-
-<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
-<tr>
-<th>Preference</th>
-<th>Default Value</th>
-<th>Options</th>
-<th>Description</th>
-</tr>
-
-<tr>
-<td class="td"><strong>upload_path</strong></td>
-<td class="td">None</td>
-<td class="td">None</td>
-<td class="td">The path to the folder where the upload should be placed. The folder must be writable and the path can be absolute or relative.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>allowed_types</strong></td>
-<td class="td">None</td>
-<td class="td">None</td>
-<td class="td">The mime types corresponding to the types of files you allow to be uploaded. Usually the file extension can be used as the mime type. Separate multiple types with a pipe.</td>
-</tr>
-
-
-<tr>
-<td class="td"><strong>overwrite</strong></td>
-<td class="td">FALSE</td>
-<td class="td">TRUE/FALSE (boolean)</td>
-<td class="td">If set to true, if a file with the same name as the one you are uploading exists, it will be overwritten. If set to false, a number will be appended to the filename if another with the same name exists.</td>
-</tr>
-
-
-<tr>
-<td class="td"><strong>max_size</strong></td>
-<td class="td">0</td>
-<td class="td">None</td>
-<td class="td">The maximum size (in kilobytes) that the file can be. Set to zero for no limit. Note: Most PHP installations have their own limit, as specified in the php.ini file. Usually 2 MB (or 2048 KB) by default.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>max_width</strong></td>
-<td class="td">0</td>
-<td class="td">None</td>
-<td class="td">The maximum width (in pixels) that the file can be. Set to zero for no limit.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>max_height</strong></td>
-<td class="td">0</td>
-<td class="td">None</td>
-<td class="td">The maximum height (in pixels) that the file can be. Set to zero for no limit.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>max_filename</strong></td>
-<td class="td">0</td>
-<td class="td">None</td>
-<td class="td">The maximum length that a file name can be. Set to zero for no limit.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>encrypt_name</strong></td>
-<td class="td">FALSE</td>
-<td class="td">TRUE/FALSE (boolean)</td>
-<td class="td">If set to TRUE the file name will be converted to a random encrypted string. This can be useful if you would like the file saved with a name that can not be discerned by the person uploading it.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>remove_spaces</strong></td>
-<td class="td">TRUE</td>
-<td class="td">TRUE/FALSE (boolean)</td>
-<td class="td">If set to TRUE, any spaces in the file name will be converted to underscores. This is recommended.</td>
-</tr>
-</table>
-
-
-<h2>Setting preferences in a config file</h2>
-
-<p>If you prefer not to set preferences using the above method, you can instead put them into a config file.
-Simply create a new file called the <var>upload.php</var>, add the <var>$config</var>
-array in that file. Then save the file in: <var>config/upload.php</var> and it will be used automatically. You
-will NOT need to use the <dfn>$this->upload->initialize</dfn> function if you save your preferences in a config file.</p>
-
-
-<h2>Function Reference</h2>
-
-<p>The following functions are available</p>
-
-
-<h2>$this->upload->do_upload()</h2>
-
-<p>Performs the upload based on the preferences you've set. Note: By default the upload routine expects the file to come from a form field
-called <dfn>userfile</dfn>, and the form must be a "multipart type:</p>
-
-<code><form method="post" action="some_action" enctype="multipart/form-data" /></code>
-
-<p>If you would like to set your own field name simply pass its value to the <dfn>do_upload</dfn> function:</p>
-
-<code>
-$field_name = "some_field_name";<br />
-$this->upload->do_upload($field_name)</code>
-
-
-<h2>$this->upload->display_errors()</h2>
-
-<p>Retrieves any error messages if the <dfn>do_upload()</dfn> function returned false. The function does not echo automatically, it
-returns the data so you can assign it however you need.</p>
-
-<h3>Formatting Errors</h3>
-<p>By default the above function wraps any errors within <p> tags. You can set your own delimiters like this:</p>
-
-<code>$this->upload->display_errors('<var><p></var>', '<var></p></var>');</code>
-
-<h2>$this->upload->data()</h2>
-
-<p>This is a helper function that returns an array containing all of the data related to the file you uploaded.
-Here is the array prototype:</p>
-
-<code>Array<br />
-(<br />
- [file_name] => mypic.jpg<br />
- [file_type] => image/jpeg<br />
- [file_path] => /path/to/your/upload/<br />
- [full_path] => /path/to/your/upload/jpg.jpg<br />
- [raw_name] => mypic<br />
- [orig_name] => mypic.jpg<br />
- [file_ext] => .jpg<br />
- [file_size] => 22.2<br />
- [is_image] => 1<br />
- [image_width] => 800<br />
- [image_height] => 600<br />
- [image_type] => jpeg<br />
- [image_size_str] => width="800" height="200"<br />
-)</code>
-
-<h3>Explanation</h3>
-
-<p>Here is an explanation of the above array items.</p>
-
-<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
-<tr><th>Item</th><th>Description</th></tr>
-
-<tr><td class="td"><strong>file_name</strong></td>
-<td class="td">The name of the file that was uploaded including the file extension.</td></tr>
-
-<tr><td class="td"><strong>file_type</strong></td>
-<td class="td">The file's Mime type</td></tr>
-
-<tr><td class="td"><strong>file_path</strong></td>
-<td class="td">The absolute server path to the file</td></tr>
-
-<tr><td class="td"><strong>full_path</strong></td>
-<td class="td">The absolute server path including the file name</td></tr>
-
-<tr><td class="td"><strong>raw_name</strong></td>
-<td class="td">The file name without the extension</td></tr>
-
-<tr><td class="td"><strong>orig_name</strong></td>
-<td class="td">The original file name. This is only useful if you use the encrypted name option.</td></tr>
-
-<tr><td class="td"><strong>file_ext</strong></td>
-<td class="td">The file extension with period</td></tr>
-
-<tr><td class="td"><strong>file_size</strong></td>
-<td class="td">The file size in kilobytes</td></tr>
-
-<tr><td class="td"><strong>is_image</strong></td>
-<td class="td">Whether the file is an image or not. 1 = image. 0 = not.</td></tr>
-
-<tr><td class="td"><strong>image_width</strong></td>
-<td class="td">Image width.</td></tr>
-
-<tr><td class="td"><strong>image_heigth</strong></td>
-<td class="td">Image height</td></tr>
-
-<tr><td class="td"><strong>image_type</strong></td>
-<td class="td">Image type. Typically the file extension without the period.</td></tr>
-
-<tr><td class="td"><strong>image_size_str</strong></td>
-<td class="td">A string containing the width and height. Useful to put into an image tag.</td></tr>
-
-
-</table>
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="encryption.html">Encryption Helper</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="form_validation.html">Form Validation Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>File Uploading Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +File Uploading Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>File Uploading Class</h1> + +<p>CodeIgniter's File Uploading Class permits files to be uploaded. You can set various +preferences, restricting the type and size of the files.</p> + + +<h2>The Process</h2> + +<p>Uploading a file involves the following general process:</p> + + +<ul> +<li>An upload form is displayed, allowing a user to select a file and upload it.</li> +<li>When the form is submitted, the file is uploaded to the destination you specify.</li> +<li>Along the way, the file is validated to make sure it is allowed to be uploaded based on the preferences you set.</li> +<li>Once uploaded, the user will be shown a success message.</li> +</ul> + +<p>To demonstrate this process here is brief tutorial. Afterward you'll find reference information.</p> + +<h2>Creating the Upload Form</h2> + + + +<p>Using a text editor, create a form called <dfn>upload_form.php</dfn>. In it, place this code and save it to your <samp>applications/views/</samp> +folder:</p> + + +<textarea class="textarea" style="width:100%" cols="50" rows="23"> +<html> +<head> +<title>Upload Form</title> +</head> +<body> + +<?php echo $error;?> + +<?php echo form_open_multipart('upload/do_upload');?> + +<input type="file" name="userfile" size="20" /> + +<br /><br /> + +<input type="submit" value="upload" /> + +</form> + +</body> +</html></textarea> + +<p>You'll notice we are using a form helper to create the opening form tag. File uploads require a multipart form, so the helper +creates the proper syntax for you. You'll also notice we have an $error variable. This is so we can show error messages in the event +the user does something wrong.</p> + + +<h2>The Success Page</h2> + +<p>Using a text editor, create a form called <dfn>upload_success.php</dfn>. +In it, place this code and save it to your <samp>applications/views/</samp> folder:</p> + +<textarea class="textarea" style="width:100%" cols="50" rows="20"><html> +<head> +<title>Upload Form</title> +</head> +<body> + +<h3>Your file was successfully uploaded!</h3> + +<ul> +<?php foreach($upload_data as $item => $value):?> +<li><?php echo $item;?>: <?php echo $value;?></li> +<?php endforeach; ?> +</ul> + +<p><?php echo anchor('upload', 'Upload Another File!'); ?></p> + +</body> +</html></textarea> + + +<h2>The Controller</h2> + +<p>Using a text editor, create a controller called <dfn>upload.php</dfn>. In it, place this code and save it to your <samp>applications/controllers/</samp> +folder:</p> + + +<textarea class="textarea" style="width:100%" cols="50" rows="43"><?php + +class Upload extends Controller { + + function Upload() + { + parent::Controller(); + $this->load->helper(array('form', 'url')); + } + + function index() + { + $this->load->view('upload_form', array('error' => ' ' )); + } + + function do_upload() + { + $config['upload_path'] = './uploads/'; + $config['allowed_types'] = 'gif|jpg|png'; + $config['max_size'] = '100'; + $config['max_width'] = '1024'; + $config['max_height'] = '768'; + + $this->load->library('upload', $config); + + if ( ! $this->upload->do_upload()) + { + $error = array('error' => $this->upload->display_errors()); + + $this->load->view('upload_form', $error); + } + else + { + $data = array('upload_data' => $this->upload->data()); + + $this->load->view('upload_success', $data); + } + } +} +?></textarea> + + +<h2>The Upload Folder</h2> + +<p>You'll need a destination folder for your uploaded images. Create a folder at the root of your CodeIgniter installation called +<dfn>uploads</dfn> and set its file permissions to 777.</p> + + +<h2>Try it!</h2> + +<p>To try your form, visit your site using a URL similar to this one:</p> + +<code>example.com/index.php/<var>upload</var>/</code> + +<p>You should see an upload form. Try uploading an image file (either a jpg, gif, or png). If the path in your +controller is correct it should work.</p> + + +<p> </p> + +<h1>Reference Guide</h1> + + +<h2>Initializing the Upload Class</h2> + +<p>Like most other classes in CodeIgniter, the Upload class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p> + +<code>$this->load->library('upload');</code> +<p>Once the Upload class is loaded, the object will be available using: <dfn>$this->upload</dfn></p> + + +<h2>Setting Preferences</h2> + +<p>Similar to other libraries, you'll control what is allowed to be upload based on your preferences. In the controller you +built above you set the following preferences:</p> + +<code>$config['upload_path'] = './uploads/';<br /> +$config['allowed_types'] = 'gif|jpg|png';<br /> +$config['max_size'] = '100';<br /> +$config['max_width'] = '1024';<br /> +$config['max_height'] = '768';<br /> +<br /> +$this->load->library('upload', $config);<br /><br /> + +// Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class:<br /> +$this->upload->initialize($config);</code> + +<p>The above preferences should be fairly self-explanatory. Below is a table describing all available preferences.</p> + + +<h2>Preferences</h2> + +<p>The following preferences are available. The default value indicates what will be used if you do not specify that preference.</p> + +<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder"> +<tr> +<th>Preference</th> +<th>Default Value</th> +<th>Options</th> +<th>Description</th> +</tr> + +<tr> +<td class="td"><strong>upload_path</strong></td> +<td class="td">None</td> +<td class="td">None</td> +<td class="td">The path to the folder where the upload should be placed. The folder must be writable and the path can be absolute or relative.</td> +</tr> + +<tr> +<td class="td"><strong>allowed_types</strong></td> +<td class="td">None</td> +<td class="td">None</td> +<td class="td">The mime types corresponding to the types of files you allow to be uploaded. Usually the file extension can be used as the mime type. Separate multiple types with a pipe.</td> +</tr> + + +<tr> +<td class="td"><strong>overwrite</strong></td> +<td class="td">FALSE</td> +<td class="td">TRUE/FALSE (boolean)</td> +<td class="td">If set to true, if a file with the same name as the one you are uploading exists, it will be overwritten. If set to false, a number will be appended to the filename if another with the same name exists.</td> +</tr> + + +<tr> +<td class="td"><strong>max_size</strong></td> +<td class="td">0</td> +<td class="td">None</td> +<td class="td">The maximum size (in kilobytes) that the file can be. Set to zero for no limit. Note: Most PHP installations have their own limit, as specified in the php.ini file. Usually 2 MB (or 2048 KB) by default.</td> +</tr> + +<tr> +<td class="td"><strong>max_width</strong></td> +<td class="td">0</td> +<td class="td">None</td> +<td class="td">The maximum width (in pixels) that the file can be. Set to zero for no limit.</td> +</tr> + +<tr> +<td class="td"><strong>max_height</strong></td> +<td class="td">0</td> +<td class="td">None</td> +<td class="td">The maximum height (in pixels) that the file can be. Set to zero for no limit.</td> +</tr> + +<tr> +<td class="td"><strong>max_filename</strong></td> +<td class="td">0</td> +<td class="td">None</td> +<td class="td">The maximum length that a file name can be. Set to zero for no limit.</td> +</tr> + +<tr> +<td class="td"><strong>encrypt_name</strong></td> +<td class="td">FALSE</td> +<td class="td">TRUE/FALSE (boolean)</td> +<td class="td">If set to TRUE the file name will be converted to a random encrypted string. This can be useful if you would like the file saved with a name that can not be discerned by the person uploading it.</td> +</tr> + +<tr> +<td class="td"><strong>remove_spaces</strong></td> +<td class="td">TRUE</td> +<td class="td">TRUE/FALSE (boolean)</td> +<td class="td">If set to TRUE, any spaces in the file name will be converted to underscores. This is recommended.</td> +</tr> +</table> + + +<h2>Setting preferences in a config file</h2> + +<p>If you prefer not to set preferences using the above method, you can instead put them into a config file. +Simply create a new file called the <var>upload.php</var>, add the <var>$config</var> +array in that file. Then save the file in: <var>config/upload.php</var> and it will be used automatically. You +will NOT need to use the <dfn>$this->upload->initialize</dfn> function if you save your preferences in a config file.</p> + + +<h2>Function Reference</h2> + +<p>The following functions are available</p> + + +<h2>$this->upload->do_upload()</h2> + +<p>Performs the upload based on the preferences you've set. Note: By default the upload routine expects the file to come from a form field +called <dfn>userfile</dfn>, and the form must be a "multipart type:</p> + +<code><form method="post" action="some_action" enctype="multipart/form-data" /></code> + +<p>If you would like to set your own field name simply pass its value to the <dfn>do_upload</dfn> function:</p> + +<code> +$field_name = "some_field_name";<br /> +$this->upload->do_upload($field_name)</code> + + +<h2>$this->upload->display_errors()</h2> + +<p>Retrieves any error messages if the <dfn>do_upload()</dfn> function returned false. The function does not echo automatically, it +returns the data so you can assign it however you need.</p> + +<h3>Formatting Errors</h3> +<p>By default the above function wraps any errors within <p> tags. You can set your own delimiters like this:</p> + +<code>$this->upload->display_errors('<var><p></var>', '<var></p></var>');</code> + +<h2>$this->upload->data()</h2> + +<p>This is a helper function that returns an array containing all of the data related to the file you uploaded. +Here is the array prototype:</p> + +<code>Array<br /> +(<br /> + [file_name] => mypic.jpg<br /> + [file_type] => image/jpeg<br /> + [file_path] => /path/to/your/upload/<br /> + [full_path] => /path/to/your/upload/jpg.jpg<br /> + [raw_name] => mypic<br /> + [orig_name] => mypic.jpg<br /> + [file_ext] => .jpg<br /> + [file_size] => 22.2<br /> + [is_image] => 1<br /> + [image_width] => 800<br /> + [image_height] => 600<br /> + [image_type] => jpeg<br /> + [image_size_str] => width="800" height="200"<br /> +)</code> + +<h3>Explanation</h3> + +<p>Here is an explanation of the above array items.</p> + +<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder"> +<tr><th>Item</th><th>Description</th></tr> + +<tr><td class="td"><strong>file_name</strong></td> +<td class="td">The name of the file that was uploaded including the file extension.</td></tr> + +<tr><td class="td"><strong>file_type</strong></td> +<td class="td">The file's Mime type</td></tr> + +<tr><td class="td"><strong>file_path</strong></td> +<td class="td">The absolute server path to the file</td></tr> + +<tr><td class="td"><strong>full_path</strong></td> +<td class="td">The absolute server path including the file name</td></tr> + +<tr><td class="td"><strong>raw_name</strong></td> +<td class="td">The file name without the extension</td></tr> + +<tr><td class="td"><strong>orig_name</strong></td> +<td class="td">The original file name. This is only useful if you use the encrypted name option.</td></tr> + +<tr><td class="td"><strong>file_ext</strong></td> +<td class="td">The file extension with period</td></tr> + +<tr><td class="td"><strong>file_size</strong></td> +<td class="td">The file size in kilobytes</td></tr> + +<tr><td class="td"><strong>is_image</strong></td> +<td class="td">Whether the file is an image or not. 1 = image. 0 = not.</td></tr> + +<tr><td class="td"><strong>image_width</strong></td> +<td class="td">Image width.</td></tr> + +<tr><td class="td"><strong>image_heigth</strong></td> +<td class="td">Image height</td></tr> + +<tr><td class="td"><strong>image_type</strong></td> +<td class="td">Image type. Typically the file extension without the period.</td></tr> + +<tr><td class="td"><strong>image_size_str</strong></td> +<td class="td">A string containing the width and height. Useful to put into an image tag.</td></tr> + + +</table> + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="encryption.html">Encryption Helper</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="form_validation.html">Form Validation Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/form_validation.html b/user_guide/libraries/form_validation.html index 63111919f..684fe9b51 100644 --- a/user_guide/libraries/form_validation.html +++ b/user_guide/libraries/form_validation.html @@ -1,1221 +1,1221 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Form Validation : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Form Validation
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-<h1>Form Validation</h1>
-
-<p>CodeIgniter provides a comprehensive form validation and data prepping class that helps minimize the amount of code you'll write.</p>
-
-<p class="important"><strong>Note:</strong> As of CodeIgniter 1.7.0, this Form Validation class supercedes the old Validation class, which is now deprecated. We
-have left the old class in the library so applications currently using it will not break, but you are encouraged to migrate to this new version.</p>
-
-<ul>
-<li><a href="#overview">Overview</a></li>
-<li><a href="#tutorial">Form Validation Tutorial</a>
-
- <ul>
- <li><a href="#theform">The Form</a></li>
- <li><a href="#thesuccesspage">The Success Page</a></li>
- <li><a href="#thecontroller">The Controller</a></li>
- <li><a href="#validationrules">Setting Validation Rules</a></li>
- <li><a href="#validationrulesasarray">Setting Validation Rules Using an Array</a></li>
- <li><a href="#cascadingrules">Cascading Rules</a></li>
- <li><a href="#preppingdata">Prepping Data</a></li>
- <li><a href="#repopulatingform">Re-populating the Form</a></li>
- <li><a href="#callbacks">Callbacks</a></li>
- <li><a href="#settingerrors">Setting Error Messages</a></li>
- <li><a href="#errordelimiters">Changing the Error Delimiters</a></li>
- <li><a href="#translatingfn">Translating Field Names</a></li>
- <li><a href="#individualerrors">Showing Errors Individually</a></li>
- <li><a href="#savingtoconfig">Saving Sets of Validation Rules to a Config File</a></li>
- <li><a href="#arraysasfields">Using Arrays as Field Names</a></li>
- </ul>
-</li>
-<li><a href="#rulereference">Rule Reference</a></li>
-<li><a href="#preppingreference">Prepping Reference</a></li>
-<li><a href="#functionreference">Function Reference</a></li>
-<li><a href="#helperreference">Helper Reference</a></li>
-
-</ul>
-
-
-
-
-
-
-<p> </p>
-
-<a name="overview"></a>
-<h1>Overview</h1>
-
-
-<p>Before explaining CodeIgniter's approach to data validation, let's describe the ideal scenario:</p>
-
-<ol>
-<li>A form is displayed.</li>
-<li>You fill it in and submit it.</li>
-<li>If you submitted something invalid, or perhaps missed a required item, the form is redisplayed containing your data
-along with an error message describing the problem.</li>
-<li>This process continues until you have submitted a valid form.</li>
-</ol>
-
-<p>On the receiving end, the script must:</p>
-
-<ol>
-<li>Check for required data.</li>
-<li>Verify that the data is of the correct type, and meets the correct criteria. For example, if a username is submitted
-it must be validated to contain only permitted characters. It must be of a minimum length,
-and not exceed a maximum length. The username can't be someone else's existing username, or perhaps even a reserved word. Etc.</li>
-<li>Sanitize the data for security.</li>
-<li>Pre-format the data if needed (Does the data need to be trimmed? HTML encoded? Etc.)</li>
-<li>Prep the data for insertion in the database.</li>
-</ol>
-
-
-<p>Although there is nothing terribly complex about the above process, it usually requires a significant
-amount of code, and to display error messages, various control structures are usually placed within the form HTML.
-Form validation, while simple to create, is generally very messy and tedious to implement.</p>
-
-<p> </p>
-
-
-<a name="tutorial"></a>
-<h1>Form Validation Tutorial</h1>
-
-<p>What follows is a "hands on" tutorial for implementing CodeIgniters Form Validation.</p>
-
-
-<p>In order to implement form validation you'll need three things:</p>
-
-<ol>
-<li>A <a href="../general/views.html">View</a> file containing a form.</li>
-<li>A View file containing a "success" message to be displayed upon successful submission.</li>
-<li>A <a href="../general/controllers.html">controller</a> function to receive and process the submitted data.</li>
-</ol>
-
-<p>Let's create those three things, using a member sign-up form as the example.</p>
-
-
-
-<a name="theform"></a>
-
-<h2>The Form</h2>
-
-<p>Using a text editor, create a form called <dfn>myform.php</dfn>. In it, place this code and save it to your <samp>applications/views/</samp>
-folder:</p>
-
-
-<textarea class="textarea" style="width:100%" cols="50" rows="30"><html>
-<head>
-<title>My Form</title>
-</head>
-<body>
-
-<?php echo validation_errors(); ?>
-
-<?php echo form_open('form'); ?>
-
-<h5>Username</h5>
-<input type="text" name="username" value="" size="50" />
-
-<h5>Password</h5>
-<input type="text" name="password" value="" size="50" />
-
-<h5>Password Confirm</h5>
-<input type="text" name="passconf" value="" size="50" />
-
-<h5>Email Address</h5>
-<input type="text" name="email" value="" size="50" />
-
-<div><input type="submit" value="Submit" /></div>
-
-</form>
-
-</body>
-</html>
-</textarea>
-
-
-
-
-<a name="thesuccesspage"></a>
-<h2>The Success Page</h2>
-
-
-<p>Using a text editor, create a form called <dfn>formsuccess.php</dfn>. In it, place this code and save it to your <samp>applications/views/</samp>
-folder:</p>
-
-
-<textarea class="textarea" style="width:100%" cols="50" rows="14">
-<html>
-<head>
-<title>My Form</title>
-</head>
-<body>
-
-<h3>Your form was successfully submitted!</h3>
-
-<p><?php echo anchor('form', 'Try it again!'); ?></p>
-
-</body>
-</html>
-</textarea>
-
-
-
-<a name="thecontroller"></a>
-<h2>The Controller</h2>
-
-<p>Using a text editor, create a controller called <dfn>form.php</dfn>. In it, place this code and save it to your <samp>applications/controllers/</samp>
-folder:</p>
-
-
-<textarea class="textarea" style="width:100%" cols="50" rows="21"><?php
-
-class Form extends Controller {
-
- function index()
- {
- $this->load->helper(array('form', 'url'));
-
- $this->load->library('form_validation');
-
- if ($this->form_validation->run() == FALSE)
- {
- $this->load->view('myform');
- }
- else
- {
- $this->load->view('formsuccess');
- }
- }
-}
-?></textarea>
-
-
-<h2>Try it!</h2>
-
-<p>To try your form, visit your site using a URL similar to this one:</p>
-
-<code>example.com/index.php/<var>form</var>/</code>
-
-<p><dfn>If you submit the form you should simply see the form reload. That's because you haven't set up any validation
-rules yet.</dfn></p>
-
-<p><strong>Since you haven't told the Form Validation class to validate anything yet, it returns <kbd>FALSE</kbd> (boolean false) by default. The <samp>run()</samp>
-function only returns <kbd>TRUE</kbd> if it has successfully applied your rules without any of them failing.</strong></p>
-
-
-<h2>Explanation</h2>
-
-<p>You'll notice several things about the above pages:</p>
-
-<p>The <dfn>form</dfn> (myform.php) is a standard web form with a couple exceptions:</p>
-
-<ol>
-<li>It uses a <dfn>form helper</dfn> to create the form opening.
-Technically, this isn't necessary. You could create the form using standard HTML. However, the benefit of using the helper
-is that it generates the action URL for you, based on the URL in your config file. This makes your application more portable in the event your URLs change.</li>
-
-<li>At the top of the form you'll notice the following function call:
-<code><?php echo validation_errors(); ?></code>
-
-<p>This function will return any error messages sent back by the validator. If there are no messages it returns an empty string.</p>
-</li>
-</ol>
-
-<p>The <dfn>controller</dfn> (form.php) has one function: <dfn>index()</dfn>. This function initializes the validation class and
-loads the <var>form helper</var> and <var>URL helper</var> used by your view files. It also <samp>runs</samp>
-the validation routine. Based on
-whether the validation was successful it either presents the form or the success page.</p>
-
-
-
-
-<a name="validationrules"></a>
-
-<h2>Setting Validation Rules</h2>
-
-<p>CodeIgniter lets you set as many validation rules as you need for a given field, cascading them in order, and it even lets you prep and pre-process the field data
-at the same time. To set validation rules you will use the <dfn>set_rules()</dfn> function:</p>
-
-<code>$this->form_validation->set_rules();</code>
-
-<p>The above function takes <strong>three</strong> parameters as input:</p>
-
-<ol>
- <li>The field name - the exact name you've given the form field.</li>
- <li>A "human" name for this field, which will be inserted into the error message. For example, if your field is named "user" you might give it a human name of "Username". <strong>Note:</strong> If you would like the field name to be stored in a language file, please see <a href="#translatingfn">Translating Field Names</a>.</li>
- <li>The validation rules for this form field.</li>
-</ol>
-
-
-<p><br />Here is an example. In your <dfn>controller</dfn> (form.php), add this code just below the validation initialization function:</p>
-
-<code>
-$this->form_validation->set_rules('username', 'Username', 'required');<br />
-$this->form_validation->set_rules('password', 'Password', 'required');<br />
-$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');<br />
-$this->form_validation->set_rules('email', 'Email', 'required');<br />
-</code>
-
-<p>Your controller should now look like this:</p>
-
-<textarea class="textarea" style="width:100%" cols="50" rows="28"><?php
-
-class Form extends Controller {
-
- function index()
- {
- $this->load->helper(array('form', 'url'));
-
- $this->load->library('form_validation');
-
- $this->form_validation->set_rules('username', 'Username', 'required');
- $this->form_validation->set_rules('password', 'Password', 'required');
- $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
- $this->form_validation->set_rules('email', 'Email', 'required');
-
- if ($this->form_validation->run() == FALSE)
- {
- $this->load->view('myform');
- }
- else
- {
- $this->load->view('formsuccess');
- }
- }
-}
-?></textarea>
-
-<p><dfn>Now submit the form with the fields blank and you should see the error messages.
-If you submit the form with all the fields populated you'll see your success page.</dfn></p>
-
-<p class="important"><strong>Note:</strong> The form fields are not yet being re-populated with the data when
-there is an error. We'll get to that shortly.</p>
-
-
-
-
-<a name="validationrulesasarray"></a>
-<h2>Setting Rules Using an Array</h2>
-
-<p>Before moving on it should be noted that the rule setting function can be passed an array if you prefer to set all your rules in one action.
-If you use this approach you must name your array keys as indicated:</p>
-
-<code>
-$config = array(<br />
- array(<br />
- 'field' => 'username', <br />
- 'label' => 'Username', <br />
- 'rules' => 'required'<br />
- ),<br />
- array(<br />
- 'field' => 'password', <br />
- 'label' => 'Password', <br />
- 'rules' => 'required'<br />
- ),<br />
- array(<br />
- 'field' => 'passconf', <br />
- 'label' => 'Password Confirmation', <br />
- 'rules' => 'required'<br />
- ), <br />
- array(<br />
- 'field' => 'email', <br />
- 'label' => 'Email', <br />
- 'rules' => 'required'<br />
- )<br />
- );<br />
-<br />
-$this->form_validation->set_rules($config);
-</code>
-
-
-
-
-
-
-<a name="cascadingrules"></a>
-<h2>Cascading Rules</h2>
-
-<p>CodeIgniter lets you pipe multiple rules together. Let's try it. Change your rules in the third parameter of rule setting function, like this:</p>
-
-<code>
-$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]');<br />
-$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');<br />
-$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');<br />
-$this->form_validation->set_rules('email', 'Email', 'required|valid_email');<br />
-</code>
-
-<p>The above code sets the following rules:</p>
-
-<ol>
-<li>The username field be no shorter than 5 characters and no longer than 12.</li>
-<li>The password field must match the password confirmation field.</li>
-<li>The email field must contain a valid email address.</li>
-</ol>
-
-<p>Give it a try! Submit your form without the proper data and you'll see new error messages that correspond to your new rules.
-There are numerous rules available which you can read about in the validation reference.</p>
-
-
-
-<a name="preppingdata"></a>
-<h2>Prepping Data</h2>
-
-<p>In addition to the validation functions like the ones we used above, you can also prep your data in various ways.
-For example, you can set up rules like this:</p>
-
-<code>
-$this->form_validation->set_rules('username', 'Username', '<kbd>trim</kbd>|required|min_length[5]|max_length[12]|<kbd>xss_clean</kbd>');<br />
-$this->form_validation->set_rules('password', 'Password', '<kbd>trim</kbd>|required|matches[passconf]|<kbd>md5</kbd>');<br />
-$this->form_validation->set_rules('passconf', 'Password Confirmation', '<kbd>trim</kbd>|required');<br />
-$this->form_validation->set_rules('email', 'Email', '<kbd>trim</kbd>|required|valid_email');<br />
-</code>
-
-
-<p>In the above example, we are "trimming" the fields, converting the password to MD5, and running the username through
-the "xss_clean" function, which removes malicious data.</p>
-
-<p><strong>Any native PHP function that accepts one parameter can be used as a rule, like <dfn>htmlspecialchars</dfn>,
-<dfn>trim</dfn>, <dfn>MD5</dfn>, etc.</strong></p>
-
-<p><strong>Note:</strong> You will generally want to use the prepping functions <strong>after</strong>
-the validation rules so if there is an error, the original data will be shown in the form.</p>
-
-
-
-
-<a name="repopulatingform"></a>
-<h2>Re-populating the form</h2>
-
-<p>Thus far we have only been dealing with errors. It's time to repopulate the form field with the submitted data. CodeIgniter offers several helper functions
-that permit you to do this. The one you will use most commonly is:</p>
-
-<code>set_value('field name')</code>
-
-
-<p>Open your <dfn>myform.php</dfn> view file and update the <strong>value</strong> in each field using the <dfn>set_value()</dfn> function:</p>
-
-<p><strong>Don't forget to include each. field name in the <dfn>set_value()</dfn> functions!</strong></p>
-
-
-<textarea class="textarea" style="width:100%" cols="50" rows="30">
-<html>
-<head>
-<title>My Form</title>
-</head>
-<body>
-
-<?php echo validation_errors(); ?>
-
-<?php echo form_open('form'); ?>
-
-<h5>Username</h5>
-<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />
-
-<h5>Password</h5>
-<input type="text" name="password" value="<?php echo set_value('password'); ?>" size="50" />
-
-<h5>Password Confirm</h5>
-<input type="text" name="passconf" value="<?php echo set_value('passconf'); ?>" size="50" />
-
-<h5>Email Address</h5>
-<input type="text" name="email" value="<?php echo set_value('email'); ?>" size="50" />
-
-<div><input type="submit" value="Submit" /></div>
-
-</form>
-
-</body>
-</html>
-</textarea>
-
-
-<p><dfn>Now reload your page and submit the form so that it triggers an error. Your form fields should now be re-populated</dfn></p>
-
-<p class="important"><strong>Note:</strong> The <a href="#functionreference">Function Reference</a> section below contains functions that
-permit you to re-populate <select> menus, radio buttons, and checkboxes.</p>
-
-
-<p><strong>Important Note:</strong> If you use an array as the name of a form field, you must supply it as an array to the function. Example:</p>
-
-<code><input type="text" name="<kbd>colors[]</kbd>" value="<?php echo set_value('<kbd>colors[]</kbd>'); ?>" size="50" /></code>
-
-<p>For more info please see the <a href="#arraysasfields">Using Arrays as Field Names</a> section below.</p>
-
-
-
-
-
-<a name="callbacks"></a>
-<h2>Callbacks: Your own Validation Functions</h2>
-
-<p>The validation system supports callbacks to your own validation functions. This permits you to extend the validation class
-to meet your needs. For example, if you need to run a database query to see if the user is choosing a unique username, you can
-create a callback function that does that. Let's create a example of this.</p>
-
-<p>In your controller, change the "username" rule to this:</p>
-
-<code>$this->form_validation->set_rules('username', 'Username', '<kbd>callback_username_check</kbd>');</code>
-
-
-<p>Then add a new function called <dfn>username_check</dfn> to your controller. Here's how your controller should now look:</p>
-
-
-<textarea class="textarea" style="width:100%" cols="50" rows="44"><?php
-
-class Form extends Controller {
-
- function index()
- {
- $this->load->helper(array('form', 'url'));
-
- $this->load->library('form_validation');
-
- $this->form_validation->set_rules('username', 'Username', 'callback_username_check');
- $this->form_validation->set_rules('password', 'Password', 'required');
- $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
- $this->form_validation->set_rules('email', 'Email', 'required');
-
- if ($this->form_validation->run() == FALSE)
- {
- $this->load->view('myform');
- }
- else
- {
- $this->load->view('formsuccess');
- }
- }
-
- function username_check($str)
- {
- if ($str == 'test')
- {
- $this->form_validation->set_message('username_check', 'The %s field can not be the word "test"');
- return FALSE;
- }
- else
- {
- return TRUE;
- }
- }
-
-}
-?></textarea>
-
-<p><dfn>Reload your form and submit it with the word "test" as the username. You can see that the form field data was passed to your
-callback function for you to process.</dfn></p>
-
-<p><strong>To invoke a callback just put the function name in a rule, with "callback_" as the rule prefix.</strong></p>
-
-<p>You can also process the form data that is passed to your callback and return it. If your callback returns anything other than a boolean TRUE/FALSE
-it is assumed that the data is your newly processed form data.</p>
-
-
-
-
-<a name="settingerrors"></a>
-<h2>Setting Error Messages</h2>
-
-
-<p>All of the native error messages are located in the following language file: <dfn>language/english/form_validation_lang.php</dfn></p>
-
-<p>To set your own custom message you can either edit that file, or use the following function:</p>
-
-<code>$this->form_validation->set_message('<var>rule</var>', '<var>Error Message</var>');</code>
-
-<p>Where <var>rule</var> corresponds to the name of a particular rule, and <var>Error Message</var> is the text you would like displayed.</p>
-
-<p>If you include <dfn>%s</dfn> in your error string, it will be replaced with the "human" name you used for your field when you set your rules.</p>
-
-<p>In the "callback" example above, the error message was set by passing the name of the function:</p>
-
-<code>$this->form_validation->set_message('username_check')</code>
-
-<p>You can also override any error message found in the language file. For example, to change the message for the "required" rule you will do this:</p>
-
-<code>$this->form_validation->set_message('required', 'Your custom message here');</code>
-
-
-
-<a name="translatingfn"></a>
-<h2>Translating Field Names</h2>
-
-<p>If you would like to store the "human" name you passed to the <dfn>set_rules()</dfn> function in a language file, and therefore make the name able to be translated, here's how:</p>
-
-<p>First, prefix your "human" name with <dfn>lang:</dfn>, as in this example:</p>
-
-<code>
-$this->form_validation->set_rules('first_name', '<kbd>lang:</kbd>first_name', 'required');<br />
-</code>
-
-<p>Then, store the name in one of your language file arrays (without the prefix):</p>
-
-<code>$lang['first_name'] = 'First Name';</code>
-
-<p><strong>Note:</strong> If you store your array item in a language file that is not loaded automatically by CI, you'll need to remember to load it in your controller using:</p>
-
-<code>$this->lang->load('file_name');</code>
-
-<p>See the <a href="language.html">Language Class</a> page for more info regarding language files.</p>
-
-
-<a name="errordelimiters"></a>
-<h2>Changing the Error Delimiters</h2>
-
-<p>By default, the Form Validation class adds a paragraph tag (<p>) around each error message shown. You can either change these delimiters globally or
-individually.</p>
-
-<ol>
-
-<li><strong>Changing delimiters Globally</strong>
-
-<p>To globally change the error delimiters, in your controller function, just after loading the Form Validation class, add this:</p>
-
-<code>$this->form_validation->set_error_delimiters('<kbd><div class="error"></kbd>', '<kbd></div></kbd>');</code>
-
-<p>In this example, we've switched to using div tags.</p>
-
-</li>
-
-<li><strong>Changing delimiters Individually</strong>
-
-<p>Each of the two error generating functions shown in this tutorial can be supplied their own delimiters as follows:</p>
-
-<code><?php echo form_error('field name', '<kbd><div class="error"></kbd>', '<kbd></div></kbd>'); ?></code>
-
-<p>Or:</p>
-
-<code><?php echo validation_errors('<kbd><div class="error"></kbd>', '<kbd></div></kbd>'); ?></code>
-
-</li>
-</ol>
-
-
-
-
-<a name="individualerrors"></a>
-<h2>Showing Errors Individually</h2>
-
-<p>If you prefer to show an error message next to each form field, rather than as a list, you can use the <dfn>form_error()</dfn> function.</p>
-
-<p>Try it! Change your form so that it looks like this:</p>
-
-<textarea class="textarea" style="width:100%" cols="50" rows="18">
-<h5>Username</h5>
-<?php echo form_error('username'); ?>
-<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />
-
-<h5>Password</h5>
-<?php echo form_error('password'); ?>
-<input type="text" name="password" value="<?php echo set_value('password'); ?>" size="50" />
-
-<h5>Password Confirm</h5>
-<?php echo form_error('passconf'); ?>
-<input type="text" name="passconf" value="<?php echo set_value('passconf'); ?>" size="50" />
-
-<h5>Email Address</h5>
-<?php echo form_error('email'); ?>
-<input type="text" name="email" value="<?php echo set_value('email'); ?>" size="50" />
-</textarea>
-
-<p>If there are no errors, nothing will be shown. If there is an error, the message will appear.</p>
-
-<p><strong>Important Note:</strong> If you use an array as the name of a form field, you must supply it as an array to the function. Example:</p>
-
-<code><?php echo form_error('<kbd>options[size]</kbd>'); ?><br />
-<input type="text" name="<kbd>options[size]</kbd>" value="<?php echo set_value("<kbd>options[size]</kbd>"); ?>" size="50" />
-</code>
-
-<p>For more info please see the <a href="#arraysasfields">Using Arrays as Field Names</a> section below.</p>
-
-
-
-
-<p> </p>
-
-
-<a name="savingtoconfig"></a>
-<h1>Saving Sets of Validation Rules to a Config File</h1>
-
-<p>A nice feature of the Form Validation class is that it permits you to store all your validation rules for your entire application in a config file. You
-can organize these rules into "groups". These groups can either be loaded automatically when a matching controller/function is called, or
-you can manually call each set as needed.</p>
-
-<h3>How to save your rules</h3>
-
-<p>To store your validation rules, simply create a file named <kbd>form_validation.php</kbd> in your <dfn>application/config/</dfn> folder.
-In that file you will place an array named <kbd>$config</kbd> with your rules. As shown earlier, the validation array will have this prototype:</p>
-
-<code>
-$config = array(<br />
- array(<br />
- 'field' => 'username', <br />
- 'label' => 'Username', <br />
- 'rules' => 'required'<br />
- ),<br />
- array(<br />
- 'field' => 'password', <br />
- 'label' => 'Password', <br />
- 'rules' => 'required'<br />
- ),<br />
- array(<br />
- 'field' => 'passconf', <br />
- 'label' => 'Password Confirmation', <br />
- 'rules' => 'required'<br />
- ), <br />
- array(<br />
- 'field' => 'email', <br />
- 'label' => 'Email', <br />
- 'rules' => 'required'<br />
- )<br />
- );<br />
-</code>
-
-<p><dfn>Your validation rule file will be loaded automatically and used when you call the run() function.</dfn></p>
-
-<p class="important">Please note that you MUST name your array $config.</p>
-
-<h3>Creating Sets of Rules</h3>
-
-<p>In order to organize your rules into "sets" requires that you place them into "sub arrays". Consider the following example, showing two sets of rules.
-We've arbitrarily called these two rules "signup" and "email". You can name your rules anything you want:</p>
-
-
-<code>$config = array(<br />
- '<kbd>signup</kbd>' => array(<br />
- array(<br />
- 'field' => 'username',<br />
- 'label' => 'Username',<br />
- 'rules' => 'required'<br />
- ),<br />
- array(<br />
- 'field' => 'password',<br />
- 'label' => 'Password',<br />
- 'rules' => 'required'<br />
- ),<br />
- array(<br />
- 'field' => 'passconf',<br />
- 'label' => 'PasswordConfirmation',<br />
- 'rules' => 'required'<br />
- ),<br />
- array(<br />
- 'field' => 'email',<br />
- 'label' => 'Email',<br />
- 'rules' => 'required'<br />
- )<br />
- ),<br />
- '<kbd>email</kbd>' => array(<br />
- array(<br />
- 'field' => 'emailaddress',<br />
- 'label' => 'EmailAddress',<br />
- 'rules' => 'required|valid_email'<br />
- ),<br />
- array(<br />
- 'field' => 'name',<br />
- 'label' => 'Name',<br />
- 'rules' => 'required|alpha'<br />
- ),<br />
- array(<br />
- 'field' => 'title',<br />
- 'label' => 'Title',<br />
- 'rules' => 'required'<br />
- ),<br />
- array(<br />
- 'field' => 'message',<br />
- 'label' => 'MessageBody',<br />
- 'rules' => 'required'<br />
- )<br />
- ) <br />
- );<br />
-</code>
-
-
-<h3>Calling a Specific Rule Group</h3>
-
-<p>In order to call a specific group you will pass its name to the <kbd>run()</kbd> function. For example, to call the <kbd>signup</kbd> rule you will do this:</p>
-
-<code>
-if ($this->form_validation->run('<kbd>signup</kbd>') == FALSE)<br />
-{<br />
- $this->load->view('myform');<br />
-}<br />
-else<br />
-{<br />
- $this->load->view('formsuccess');<br />
-}<br />
-</code>
-
-
-
-<h3>Associating a Controller Function with a Rule Group</h3>
-
-<p>An alternate (and more automatic) method of calling a rule group is to name it according to the controller class/function you intend to use it with. For example, let's say you
-have a controller named <kbd>Member</kbd> and a function named <kbd>signup</kbd>. Here's what your class might look like:</p>
-
-<code>
-<?php<br /><br />
-class <kbd>Member</kbd> extends Controller {<br />
-<br />
- function <kbd>signup</kbd>()<br />
- { <br />
- $this->load->library('form_validation');<br />
- <br />
- if ($this->form_validation->run() == FALSE)<br />
- {<br />
- $this->load->view('myform');<br />
- }<br />
- else<br />
- {<br />
- $this->load->view('formsuccess');<br />
- }<br />
- }<br />
-}<br />
-?></code>
-
-<p>In your validation config file, you will name your rule group <kbd>member/signup</kbd>:</p>
-
-
-<code>$config = array(<br />
- '<kbd>member/signup</kbd>' = array(<br />
- array(<br />
- 'field' => 'username',<br />
- 'label' => 'Username',<br />
- 'rules' => 'required'<br />
- ),<br />
- array(<br />
- 'field' => 'password',<br />
- 'label' => 'Password',<br />
- 'rules' => 'required'<br />
- ),<br />
- array(<br />
- 'field' => 'passconf',<br />
- 'label' => 'PasswordConfirmation',<br />
- 'rules' => 'required'<br />
- ),<br />
- array(<br />
- 'field' => 'email',<br />
- 'label' => 'Email',<br />
- 'rules' => 'required'<br />
- )<br />
- )<br />
- );<br />
-</code>
-
-<p><dfn>When a rule group is named identically to a controller class/function it will be used automatically when the run() function is invoked from that class/function.</dfn></p>
-
-<p> </p>
-
-
-<a name="arraysasfields"></a>
-<h1>Using Arrays as Field Names</h1>
-
-<p>The Form Validation class supports the use of arrays as field names. Consider this example:</p>
-
-<code><input type="text" name="<kbd>options[]</kbd>" value="" size="50" /></code>
-
-<p>If you do use an array as a field name, you must use the EXACT array name in the <a href="#helperreference">Helper Functions</a> that require the field name,
-and as your Validation Rule field name.</p>
-
-<p>For example, to set a rule for the above field you would use:</p>
-
-<code>$this->form_validation->set_rules('<kbd>options[]</kbd>', 'Options', 'required');</code>
-
-<p>Or, to show an error for the above field you would use:</p>
-
-<code><?php echo form_error('<kbd>options[]</kbd>'); ?></code>
-
-<p>Or to re-populate the field you would use:</p>
-
-<code><input type="text" name="<kbd>options[]</kbd>" value="<kbd><?php echo set_value('<kbd>options[]</kbd>'); ?></kbd>" size="50" /></code>
-
-<p>You can use multidimensional arrays as field names as well. For example:</p>
-
-<code><input type="text" name="<kbd>options[size]</kbd>" value="" size="50" /></code>
-
-<p>Or even:</p>
-
-<code><input type="text" name="<kbd>sports[nba][basketball]</kbd>" value="" size="50" /></code>
-
-<p>As with our first example, you must use the exact array name in the helper functions:</p>
-
-<code><?php echo form_error('<kbd>sports[nba][basketball]</kbd>'); ?></code>
-
-<p>If you are using checkboxes (or other fields) that have multiple options, don't forget to leave an empty bracket after each option, so that all selections will be added to the
-POST array:</p>
-
-<code>
-<input type="checkbox" name="<kbd>options[]</kbd>" value="red" /><br />
-<input type="checkbox" name="<kbd>options[]</kbd>" value="blue" /><br />
-<input type="checkbox" name="<kbd>options[]</kbd>" value="green" />
-</code>
-
-<p>Or if you use a multidimensional array:</p>
-
-<code>
-<input type="checkbox" name="<kbd>options[color][]</kbd>" value="red" /><br />
-<input type="checkbox" name="<kbd>options[color][]</kbd>" value="blue" /><br />
-<input type="checkbox" name="<kbd>options[color][]</kbd>" value="green" />
-</code>
-
-<p>When you use a helper function you'll include the bracket as well:</p>
-
-<code><?php echo form_error('<kbd>options[color][]</kbd>'); ?></code>
-
-
-
-
-<p> </p>
-
-
-<a name="rulereference"></a>
-<h1>Rule Reference</h1>
-
-<p>The following is a list of all the native rules that are available to use:</p>
-
-
-
-<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
-<tr>
-<th>Rule</th>
-<th>Parameter</th>
-<th>Description</th>
-<th>Example</th>
-</tr><tr>
-
-<td class="td"><strong>required</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the form element is empty.</td>
-<td class="td"> </td>
-</tr><tr>
-
-<td class="td"><strong>matches</strong></td>
-<td class="td">Yes</td>
-<td class="td">Returns FALSE if the form element does not match the one in the parameter.</td>
-<td class="td">matches[form_item]</td>
-</tr><tr>
-
-<td class="td"><strong>min_length</strong></td>
-<td class="td">Yes</td>
-<td class="td">Returns FALSE if the form element is shorter then the parameter value.</td>
-<td class="td">min_length[6]</td>
-</tr><tr>
-
-<td class="td"><strong>max_length</strong></td>
-<td class="td">Yes</td>
-<td class="td">Returns FALSE if the form element is longer then the parameter value.</td>
-<td class="td">max_length[12]</td>
-</tr><tr>
-
-<td class="td"><strong>exact_length</strong></td>
-<td class="td">Yes</td>
-<td class="td">Returns FALSE if the form element is not exactly the parameter value.</td>
-<td class="td">exact_length[8]</td>
-</tr><tr>
-
-<td class="td"><strong>alpha</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the form element contains anything other than alphabetical characters.</td>
-<td class="td"> </td>
-</tr><tr>
-
-<td class="td"><strong>alpha_numeric</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the form element contains anything other than alpha-numeric characters.</td>
-<td class="td"> </td>
-</tr><tr>
-
-<td class="td"><strong>alpha_dash</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the form element contains anything other than alpha-numeric characters, underscores or dashes.</td>
-<td class="td"> </td>
-</tr>
-
-<tr>
-<td class="td"><strong>numeric</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the form element contains anything other than numeric characters.</td>
-<td class="td"> </td>
-</tr>
-
-<tr>
-<td class="td"><strong>integer</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the form element contains anything other than an integer.</td>
-<td class="td"> </td>
-</tr>
-
-<tr>
-<td class="td"><strong>is_natural</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the form element contains anything other than a natural number: 0, 1, 2, 3, etc.</td>
-<td class="td"> </td>
-</tr>
-
-<tr>
-<td class="td"><strong>is_natural_no_zero</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the form element contains anything other than a natural number, but not zero: 1, 2, 3, etc.</td>
-<td class="td"> </td>
-</tr>
-
-<tr>
-<td class="td"><strong>valid_email</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the form element does not contain a valid email address.</td>
-<td class="td"> </td>
-</tr>
-
-<tr>
-<td class="td"><strong>valid_emails</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if any value provided in a comma separated list is not a valid email.</td>
-<td class="td"> </td>
-</tr>
-
-<tr>
-<td class="td"><strong>valid_ip</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the supplied IP is not valid.</td>
-<td class="td"> </td>
-</tr>
-
-<tr>
-<td class="td"><strong>valid_base64</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the supplied string contains anything other than valid Base64 characters.</td>
-<td class="td"> </td>
-</tr>
-
-
-</table>
-
-<p><strong>Note:</strong> These rules can also be called as discrete functions. For example:</p>
-
-<code>$this->form_validation->required($string);</code>
-
-<p class="important"><strong>Note:</strong> You can also use any native PHP functions that permit one parameter.</p>
-
-
-
-<p> </p>
-
-<a name="preppingreference"></a>
-<h1>Prepping Reference</h1>
-
-<p>The following is a list of all the prepping functions that are available to use:</p>
-
-
-
-<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
-<tr>
-<th>Name</th>
-<th>Parameter</th>
-<th>Description</th>
-</tr><tr>
-
-<td class="td"><strong>xss_clean</strong></td>
-<td class="td">No</td>
-<td class="td">Runs the data through the XSS filtering function, described in the <a href="input.html">Input Class</a> page.</td>
-</tr><tr>
-
-<td class="td"><strong>prep_for_form</strong></td>
-<td class="td">No</td>
-<td class="td">Converts special characters so that HTML data can be shown in a form field without breaking it.</td>
-</tr><tr>
-
-<td class="td"><strong>prep_url</strong></td>
-<td class="td">No</td>
-<td class="td">Adds "http://" to URLs if missing.</td>
-</tr><tr>
-
-<td class="td"><strong>strip_image_tags</strong></td>
-<td class="td">No</td>
-<td class="td">Strips the HTML from image tags leaving the raw URL.</td>
-</tr><tr>
-
-<td class="td"><strong>encode_php_tags</strong></td>
-<td class="td">No</td>
-<td class="td">Converts PHP tags to entities.</td>
-</tr>
-
-</table>
-
-<p class="important"><strong>Note:</strong> You can also use any native PHP functions that permit one parameter,
-like <kbd>trim</kbd>, <kbd>htmlspecialchars</kbd>, <kbd>urldecode</kbd>, etc.</p>
-
-
-
-
-
-
-
-<p> </p>
-
-<a name="functionreference"></a>
-<h1>Function Reference</h1>
-
-<p>The following functions are intended for use in your controller functions.</p>
-
-<h2>$this->form_validation->set_rule();</h2>
-
-<p>Permits you to set validation rules, as described in the tutorial sections above:</p>
-
-<ul>
-<li><a href="#validationrules">Setting Validation Rules</a></li>
-<li><a href="#savingtoconfig">Saving Groups of Validation Rules to a Config File</a></li>
-</ul>
-
-
-<h2>$this->form_validation->run();</h2>
-
-<p>Runs the validation routines. Returns boolean TRUE on success and FALSE on failure. You can optionally pass the name of the validation
-group via the function, as described in: <a href="#savingtoconfig">Saving Groups of Validation Rules to a Config File</a>.</p>
-
-
-<h2>$this->form_validation->set_message();</h2>
-
-<p>Permits you to set custom error messages. See <a href="#settingerrors">Setting Error Messages</a> above.</p>
-
-
-<p> </p>
-
-<a name="helperreference"></a>
-<h1>Helper Reference</h1>
-
-<p>The following helper functions are available for use in the view files containing your forms. Note that these are procedural functions, so they
-<strong>do not</strong> require you to prepend them with $this->form_validation.</p>
-
-<h2>form_error()</h2>
-
-<p>Shows an individual error message associated with the field name supplied to the function. Example:</p>
-
-<code><?php echo form_error('username'); ?></code>
-
-<p>The error delimiters can be optionally specified. See the <a href="#errordelimiters">Changing the Error Delimiters</a> section above.</p>
-
-
-
-<h2>validation_errors()</h2>
-<p>Shows all error messages as a string: Example:</p>
-
-<code><?php echo validation_errors(); ?></code>
-
-<p>The error delimiters can be optionally specified. See the <a href="#errordelimiters">Changing the Error Delimiters</a> section above.</p>
-
-
-
-<h2>set_value()</h2>
-
-<p>Permits you to set the value of an input form or textarea. You must supply the field name via the first parameter of the function.
-The second (optional) parameter allows you to set a default value for the form. Example:</p>
-
-<code><input type="text" name="quantity" value="<dfn><?php echo set_value('quantity', '0'); ?></dfn>" size="50" /></code>
-
-<p>The above form will show "0" when loaded for the first time.</p>
-
-<h2>set_select()</h2>
-
-<p>If you use a <dfn><select></dfn> menu, this function permits you to display the menu item that was selected. The first parameter
-must contain the name of the select menu, the second parameter must contain the value of
-each item, and the third (optional) parameter lets you set an item as the default (use boolean TRUE/FALSE).</p>
-
-<p>Example:</p>
-
-<code>
-<select name="myselect"><br />
-<option value="one" <dfn><?php echo set_select('myselect', 'one', TRUE); ?></dfn> >One</option><br />
-<option value="two" <dfn><?php echo set_select('myselect', 'two'); ?></dfn> >Two</option><br />
-<option value="three" <dfn><?php echo set_select('myselect', 'three'); ?></dfn> >Three</option><br />
-</select>
-</code>
-
-
-<h2>set_checkbox()</h2>
-
-<p>Permits you to display a checkbox in the state it was submitted. The first parameter
-must contain the name of the checkbox, the second parameter must contain its value, and the third (optional) parameter lets you set an item as the default (use boolean TRUE/FALSE). Example:</p>
-
-<code><input type="checkbox" name="mycheck[]" value="1" <dfn><?php echo set_checkbox('mycheck[]', '1'); ?></dfn> /><br />
-<input type="checkbox" name="mycheck[]" value="2" <dfn><?php echo set_checkbox('mycheck[]', '2'); ?></dfn> /></code>
-
-
-<h2>set_radio()</h2>
-
-<p>Permits you to display radio buttons in the state they were submitted. This function is identical to the <strong>set_checkbox()</strong> function above.</p>
-
-<code><input type="radio" name="myradio" value="1" <dfn><?php echo set_radio('myradio', '1', TRUE); ?></dfn> /><br />
-<input type="radio" name="myradio" value="2" <dfn><?php echo set_radio('myradio', '2'); ?></dfn> /></code>
-
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="file_uploading.html">File Uploading Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="ftp.html">FTP Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Form Validation : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Form Validation +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + +<h1>Form Validation</h1> + +<p>CodeIgniter provides a comprehensive form validation and data prepping class that helps minimize the amount of code you'll write.</p> + +<p class="important"><strong>Note:</strong> As of CodeIgniter 1.7.0, this Form Validation class supercedes the old Validation class, which is now deprecated. We +have left the old class in the library so applications currently using it will not break, but you are encouraged to migrate to this new version.</p> + +<ul> +<li><a href="#overview">Overview</a></li> +<li><a href="#tutorial">Form Validation Tutorial</a> + + <ul> + <li><a href="#theform">The Form</a></li> + <li><a href="#thesuccesspage">The Success Page</a></li> + <li><a href="#thecontroller">The Controller</a></li> + <li><a href="#validationrules">Setting Validation Rules</a></li> + <li><a href="#validationrulesasarray">Setting Validation Rules Using an Array</a></li> + <li><a href="#cascadingrules">Cascading Rules</a></li> + <li><a href="#preppingdata">Prepping Data</a></li> + <li><a href="#repopulatingform">Re-populating the Form</a></li> + <li><a href="#callbacks">Callbacks</a></li> + <li><a href="#settingerrors">Setting Error Messages</a></li> + <li><a href="#errordelimiters">Changing the Error Delimiters</a></li> + <li><a href="#translatingfn">Translating Field Names</a></li> + <li><a href="#individualerrors">Showing Errors Individually</a></li> + <li><a href="#savingtoconfig">Saving Sets of Validation Rules to a Config File</a></li> + <li><a href="#arraysasfields">Using Arrays as Field Names</a></li> + </ul> +</li> +<li><a href="#rulereference">Rule Reference</a></li> +<li><a href="#preppingreference">Prepping Reference</a></li> +<li><a href="#functionreference">Function Reference</a></li> +<li><a href="#helperreference">Helper Reference</a></li> + +</ul> + + + + + + +<p> </p> + +<a name="overview"></a> +<h1>Overview</h1> + + +<p>Before explaining CodeIgniter's approach to data validation, let's describe the ideal scenario:</p> + +<ol> +<li>A form is displayed.</li> +<li>You fill it in and submit it.</li> +<li>If you submitted something invalid, or perhaps missed a required item, the form is redisplayed containing your data +along with an error message describing the problem.</li> +<li>This process continues until you have submitted a valid form.</li> +</ol> + +<p>On the receiving end, the script must:</p> + +<ol> +<li>Check for required data.</li> +<li>Verify that the data is of the correct type, and meets the correct criteria. For example, if a username is submitted +it must be validated to contain only permitted characters. It must be of a minimum length, +and not exceed a maximum length. The username can't be someone else's existing username, or perhaps even a reserved word. Etc.</li> +<li>Sanitize the data for security.</li> +<li>Pre-format the data if needed (Does the data need to be trimmed? HTML encoded? Etc.)</li> +<li>Prep the data for insertion in the database.</li> +</ol> + + +<p>Although there is nothing terribly complex about the above process, it usually requires a significant +amount of code, and to display error messages, various control structures are usually placed within the form HTML. +Form validation, while simple to create, is generally very messy and tedious to implement.</p> + +<p> </p> + + +<a name="tutorial"></a> +<h1>Form Validation Tutorial</h1> + +<p>What follows is a "hands on" tutorial for implementing CodeIgniters Form Validation.</p> + + +<p>In order to implement form validation you'll need three things:</p> + +<ol> +<li>A <a href="../general/views.html">View</a> file containing a form.</li> +<li>A View file containing a "success" message to be displayed upon successful submission.</li> +<li>A <a href="../general/controllers.html">controller</a> function to receive and process the submitted data.</li> +</ol> + +<p>Let's create those three things, using a member sign-up form as the example.</p> + + + +<a name="theform"></a> + +<h2>The Form</h2> + +<p>Using a text editor, create a form called <dfn>myform.php</dfn>. In it, place this code and save it to your <samp>applications/views/</samp> +folder:</p> + + +<textarea class="textarea" style="width:100%" cols="50" rows="30"><html> +<head> +<title>My Form</title> +</head> +<body> + +<?php echo validation_errors(); ?> + +<?php echo form_open('form'); ?> + +<h5>Username</h5> +<input type="text" name="username" value="" size="50" /> + +<h5>Password</h5> +<input type="text" name="password" value="" size="50" /> + +<h5>Password Confirm</h5> +<input type="text" name="passconf" value="" size="50" /> + +<h5>Email Address</h5> +<input type="text" name="email" value="" size="50" /> + +<div><input type="submit" value="Submit" /></div> + +</form> + +</body> +</html> +</textarea> + + + + +<a name="thesuccesspage"></a> +<h2>The Success Page</h2> + + +<p>Using a text editor, create a form called <dfn>formsuccess.php</dfn>. In it, place this code and save it to your <samp>applications/views/</samp> +folder:</p> + + +<textarea class="textarea" style="width:100%" cols="50" rows="14"> +<html> +<head> +<title>My Form</title> +</head> +<body> + +<h3>Your form was successfully submitted!</h3> + +<p><?php echo anchor('form', 'Try it again!'); ?></p> + +</body> +</html> +</textarea> + + + +<a name="thecontroller"></a> +<h2>The Controller</h2> + +<p>Using a text editor, create a controller called <dfn>form.php</dfn>. In it, place this code and save it to your <samp>applications/controllers/</samp> +folder:</p> + + +<textarea class="textarea" style="width:100%" cols="50" rows="21"><?php + +class Form extends Controller { + + function index() + { + $this->load->helper(array('form', 'url')); + + $this->load->library('form_validation'); + + if ($this->form_validation->run() == FALSE) + { + $this->load->view('myform'); + } + else + { + $this->load->view('formsuccess'); + } + } +} +?></textarea> + + +<h2>Try it!</h2> + +<p>To try your form, visit your site using a URL similar to this one:</p> + +<code>example.com/index.php/<var>form</var>/</code> + +<p><dfn>If you submit the form you should simply see the form reload. That's because you haven't set up any validation +rules yet.</dfn></p> + +<p><strong>Since you haven't told the Form Validation class to validate anything yet, it returns <kbd>FALSE</kbd> (boolean false) by default. The <samp>run()</samp> +function only returns <kbd>TRUE</kbd> if it has successfully applied your rules without any of them failing.</strong></p> + + +<h2>Explanation</h2> + +<p>You'll notice several things about the above pages:</p> + +<p>The <dfn>form</dfn> (myform.php) is a standard web form with a couple exceptions:</p> + +<ol> +<li>It uses a <dfn>form helper</dfn> to create the form opening. +Technically, this isn't necessary. You could create the form using standard HTML. However, the benefit of using the helper +is that it generates the action URL for you, based on the URL in your config file. This makes your application more portable in the event your URLs change.</li> + +<li>At the top of the form you'll notice the following function call: +<code><?php echo validation_errors(); ?></code> + +<p>This function will return any error messages sent back by the validator. If there are no messages it returns an empty string.</p> +</li> +</ol> + +<p>The <dfn>controller</dfn> (form.php) has one function: <dfn>index()</dfn>. This function initializes the validation class and +loads the <var>form helper</var> and <var>URL helper</var> used by your view files. It also <samp>runs</samp> +the validation routine. Based on +whether the validation was successful it either presents the form or the success page.</p> + + + + +<a name="validationrules"></a> + +<h2>Setting Validation Rules</h2> + +<p>CodeIgniter lets you set as many validation rules as you need for a given field, cascading them in order, and it even lets you prep and pre-process the field data +at the same time. To set validation rules you will use the <dfn>set_rules()</dfn> function:</p> + +<code>$this->form_validation->set_rules();</code> + +<p>The above function takes <strong>three</strong> parameters as input:</p> + +<ol> + <li>The field name - the exact name you've given the form field.</li> + <li>A "human" name for this field, which will be inserted into the error message. For example, if your field is named "user" you might give it a human name of "Username". <strong>Note:</strong> If you would like the field name to be stored in a language file, please see <a href="#translatingfn">Translating Field Names</a>.</li> + <li>The validation rules for this form field.</li> +</ol> + + +<p><br />Here is an example. In your <dfn>controller</dfn> (form.php), add this code just below the validation initialization function:</p> + +<code> +$this->form_validation->set_rules('username', 'Username', 'required');<br /> +$this->form_validation->set_rules('password', 'Password', 'required');<br /> +$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');<br /> +$this->form_validation->set_rules('email', 'Email', 'required');<br /> +</code> + +<p>Your controller should now look like this:</p> + +<textarea class="textarea" style="width:100%" cols="50" rows="28"><?php + +class Form extends Controller { + + function index() + { + $this->load->helper(array('form', 'url')); + + $this->load->library('form_validation'); + + $this->form_validation->set_rules('username', 'Username', 'required'); + $this->form_validation->set_rules('password', 'Password', 'required'); + $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required'); + $this->form_validation->set_rules('email', 'Email', 'required'); + + if ($this->form_validation->run() == FALSE) + { + $this->load->view('myform'); + } + else + { + $this->load->view('formsuccess'); + } + } +} +?></textarea> + +<p><dfn>Now submit the form with the fields blank and you should see the error messages. +If you submit the form with all the fields populated you'll see your success page.</dfn></p> + +<p class="important"><strong>Note:</strong> The form fields are not yet being re-populated with the data when +there is an error. We'll get to that shortly.</p> + + + + +<a name="validationrulesasarray"></a> +<h2>Setting Rules Using an Array</h2> + +<p>Before moving on it should be noted that the rule setting function can be passed an array if you prefer to set all your rules in one action. +If you use this approach you must name your array keys as indicated:</p> + +<code> +$config = array(<br /> + array(<br /> + 'field' => 'username', <br /> + 'label' => 'Username', <br /> + 'rules' => 'required'<br /> + ),<br /> + array(<br /> + 'field' => 'password', <br /> + 'label' => 'Password', <br /> + 'rules' => 'required'<br /> + ),<br /> + array(<br /> + 'field' => 'passconf', <br /> + 'label' => 'Password Confirmation', <br /> + 'rules' => 'required'<br /> + ), <br /> + array(<br /> + 'field' => 'email', <br /> + 'label' => 'Email', <br /> + 'rules' => 'required'<br /> + )<br /> + );<br /> +<br /> +$this->form_validation->set_rules($config); +</code> + + + + + + +<a name="cascadingrules"></a> +<h2>Cascading Rules</h2> + +<p>CodeIgniter lets you pipe multiple rules together. Let's try it. Change your rules in the third parameter of rule setting function, like this:</p> + +<code> +$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]');<br /> +$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');<br /> +$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');<br /> +$this->form_validation->set_rules('email', 'Email', 'required|valid_email');<br /> +</code> + +<p>The above code sets the following rules:</p> + +<ol> +<li>The username field be no shorter than 5 characters and no longer than 12.</li> +<li>The password field must match the password confirmation field.</li> +<li>The email field must contain a valid email address.</li> +</ol> + +<p>Give it a try! Submit your form without the proper data and you'll see new error messages that correspond to your new rules. +There are numerous rules available which you can read about in the validation reference.</p> + + + +<a name="preppingdata"></a> +<h2>Prepping Data</h2> + +<p>In addition to the validation functions like the ones we used above, you can also prep your data in various ways. +For example, you can set up rules like this:</p> + +<code> +$this->form_validation->set_rules('username', 'Username', '<kbd>trim</kbd>|required|min_length[5]|max_length[12]|<kbd>xss_clean</kbd>');<br /> +$this->form_validation->set_rules('password', 'Password', '<kbd>trim</kbd>|required|matches[passconf]|<kbd>md5</kbd>');<br /> +$this->form_validation->set_rules('passconf', 'Password Confirmation', '<kbd>trim</kbd>|required');<br /> +$this->form_validation->set_rules('email', 'Email', '<kbd>trim</kbd>|required|valid_email');<br /> +</code> + + +<p>In the above example, we are "trimming" the fields, converting the password to MD5, and running the username through +the "xss_clean" function, which removes malicious data.</p> + +<p><strong>Any native PHP function that accepts one parameter can be used as a rule, like <dfn>htmlspecialchars</dfn>, +<dfn>trim</dfn>, <dfn>MD5</dfn>, etc.</strong></p> + +<p><strong>Note:</strong> You will generally want to use the prepping functions <strong>after</strong> +the validation rules so if there is an error, the original data will be shown in the form.</p> + + + + +<a name="repopulatingform"></a> +<h2>Re-populating the form</h2> + +<p>Thus far we have only been dealing with errors. It's time to repopulate the form field with the submitted data. CodeIgniter offers several helper functions +that permit you to do this. The one you will use most commonly is:</p> + +<code>set_value('field name')</code> + + +<p>Open your <dfn>myform.php</dfn> view file and update the <strong>value</strong> in each field using the <dfn>set_value()</dfn> function:</p> + +<p><strong>Don't forget to include each. field name in the <dfn>set_value()</dfn> functions!</strong></p> + + +<textarea class="textarea" style="width:100%" cols="50" rows="30"> +<html> +<head> +<title>My Form</title> +</head> +<body> + +<?php echo validation_errors(); ?> + +<?php echo form_open('form'); ?> + +<h5>Username</h5> +<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" /> + +<h5>Password</h5> +<input type="text" name="password" value="<?php echo set_value('password'); ?>" size="50" /> + +<h5>Password Confirm</h5> +<input type="text" name="passconf" value="<?php echo set_value('passconf'); ?>" size="50" /> + +<h5>Email Address</h5> +<input type="text" name="email" value="<?php echo set_value('email'); ?>" size="50" /> + +<div><input type="submit" value="Submit" /></div> + +</form> + +</body> +</html> +</textarea> + + +<p><dfn>Now reload your page and submit the form so that it triggers an error. Your form fields should now be re-populated</dfn></p> + +<p class="important"><strong>Note:</strong> The <a href="#functionreference">Function Reference</a> section below contains functions that +permit you to re-populate <select> menus, radio buttons, and checkboxes.</p> + + +<p><strong>Important Note:</strong> If you use an array as the name of a form field, you must supply it as an array to the function. Example:</p> + +<code><input type="text" name="<kbd>colors[]</kbd>" value="<?php echo set_value('<kbd>colors[]</kbd>'); ?>" size="50" /></code> + +<p>For more info please see the <a href="#arraysasfields">Using Arrays as Field Names</a> section below.</p> + + + + + +<a name="callbacks"></a> +<h2>Callbacks: Your own Validation Functions</h2> + +<p>The validation system supports callbacks to your own validation functions. This permits you to extend the validation class +to meet your needs. For example, if you need to run a database query to see if the user is choosing a unique username, you can +create a callback function that does that. Let's create a example of this.</p> + +<p>In your controller, change the "username" rule to this:</p> + +<code>$this->form_validation->set_rules('username', 'Username', '<kbd>callback_username_check</kbd>');</code> + + +<p>Then add a new function called <dfn>username_check</dfn> to your controller. Here's how your controller should now look:</p> + + +<textarea class="textarea" style="width:100%" cols="50" rows="44"><?php + +class Form extends Controller { + + function index() + { + $this->load->helper(array('form', 'url')); + + $this->load->library('form_validation'); + + $this->form_validation->set_rules('username', 'Username', 'callback_username_check'); + $this->form_validation->set_rules('password', 'Password', 'required'); + $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required'); + $this->form_validation->set_rules('email', 'Email', 'required'); + + if ($this->form_validation->run() == FALSE) + { + $this->load->view('myform'); + } + else + { + $this->load->view('formsuccess'); + } + } + + function username_check($str) + { + if ($str == 'test') + { + $this->form_validation->set_message('username_check', 'The %s field can not be the word "test"'); + return FALSE; + } + else + { + return TRUE; + } + } + +} +?></textarea> + +<p><dfn>Reload your form and submit it with the word "test" as the username. You can see that the form field data was passed to your +callback function for you to process.</dfn></p> + +<p><strong>To invoke a callback just put the function name in a rule, with "callback_" as the rule prefix.</strong></p> + +<p>You can also process the form data that is passed to your callback and return it. If your callback returns anything other than a boolean TRUE/FALSE +it is assumed that the data is your newly processed form data.</p> + + + + +<a name="settingerrors"></a> +<h2>Setting Error Messages</h2> + + +<p>All of the native error messages are located in the following language file: <dfn>language/english/form_validation_lang.php</dfn></p> + +<p>To set your own custom message you can either edit that file, or use the following function:</p> + +<code>$this->form_validation->set_message('<var>rule</var>', '<var>Error Message</var>');</code> + +<p>Where <var>rule</var> corresponds to the name of a particular rule, and <var>Error Message</var> is the text you would like displayed.</p> + +<p>If you include <dfn>%s</dfn> in your error string, it will be replaced with the "human" name you used for your field when you set your rules.</p> + +<p>In the "callback" example above, the error message was set by passing the name of the function:</p> + +<code>$this->form_validation->set_message('username_check')</code> + +<p>You can also override any error message found in the language file. For example, to change the message for the "required" rule you will do this:</p> + +<code>$this->form_validation->set_message('required', 'Your custom message here');</code> + + + +<a name="translatingfn"></a> +<h2>Translating Field Names</h2> + +<p>If you would like to store the "human" name you passed to the <dfn>set_rules()</dfn> function in a language file, and therefore make the name able to be translated, here's how:</p> + +<p>First, prefix your "human" name with <dfn>lang:</dfn>, as in this example:</p> + +<code> +$this->form_validation->set_rules('first_name', '<kbd>lang:</kbd>first_name', 'required');<br /> +</code> + +<p>Then, store the name in one of your language file arrays (without the prefix):</p> + +<code>$lang['first_name'] = 'First Name';</code> + +<p><strong>Note:</strong> If you store your array item in a language file that is not loaded automatically by CI, you'll need to remember to load it in your controller using:</p> + +<code>$this->lang->load('file_name');</code> + +<p>See the <a href="language.html">Language Class</a> page for more info regarding language files.</p> + + +<a name="errordelimiters"></a> +<h2>Changing the Error Delimiters</h2> + +<p>By default, the Form Validation class adds a paragraph tag (<p>) around each error message shown. You can either change these delimiters globally or +individually.</p> + +<ol> + +<li><strong>Changing delimiters Globally</strong> + +<p>To globally change the error delimiters, in your controller function, just after loading the Form Validation class, add this:</p> + +<code>$this->form_validation->set_error_delimiters('<kbd><div class="error"></kbd>', '<kbd></div></kbd>');</code> + +<p>In this example, we've switched to using div tags.</p> + +</li> + +<li><strong>Changing delimiters Individually</strong> + +<p>Each of the two error generating functions shown in this tutorial can be supplied their own delimiters as follows:</p> + +<code><?php echo form_error('field name', '<kbd><div class="error"></kbd>', '<kbd></div></kbd>'); ?></code> + +<p>Or:</p> + +<code><?php echo validation_errors('<kbd><div class="error"></kbd>', '<kbd></div></kbd>'); ?></code> + +</li> +</ol> + + + + +<a name="individualerrors"></a> +<h2>Showing Errors Individually</h2> + +<p>If you prefer to show an error message next to each form field, rather than as a list, you can use the <dfn>form_error()</dfn> function.</p> + +<p>Try it! Change your form so that it looks like this:</p> + +<textarea class="textarea" style="width:100%" cols="50" rows="18"> +<h5>Username</h5> +<?php echo form_error('username'); ?> +<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" /> + +<h5>Password</h5> +<?php echo form_error('password'); ?> +<input type="text" name="password" value="<?php echo set_value('password'); ?>" size="50" /> + +<h5>Password Confirm</h5> +<?php echo form_error('passconf'); ?> +<input type="text" name="passconf" value="<?php echo set_value('passconf'); ?>" size="50" /> + +<h5>Email Address</h5> +<?php echo form_error('email'); ?> +<input type="text" name="email" value="<?php echo set_value('email'); ?>" size="50" /> +</textarea> + +<p>If there are no errors, nothing will be shown. If there is an error, the message will appear.</p> + +<p><strong>Important Note:</strong> If you use an array as the name of a form field, you must supply it as an array to the function. Example:</p> + +<code><?php echo form_error('<kbd>options[size]</kbd>'); ?><br /> +<input type="text" name="<kbd>options[size]</kbd>" value="<?php echo set_value("<kbd>options[size]</kbd>"); ?>" size="50" /> +</code> + +<p>For more info please see the <a href="#arraysasfields">Using Arrays as Field Names</a> section below.</p> + + + + +<p> </p> + + +<a name="savingtoconfig"></a> +<h1>Saving Sets of Validation Rules to a Config File</h1> + +<p>A nice feature of the Form Validation class is that it permits you to store all your validation rules for your entire application in a config file. You +can organize these rules into "groups". These groups can either be loaded automatically when a matching controller/function is called, or +you can manually call each set as needed.</p> + +<h3>How to save your rules</h3> + +<p>To store your validation rules, simply create a file named <kbd>form_validation.php</kbd> in your <dfn>application/config/</dfn> folder. +In that file you will place an array named <kbd>$config</kbd> with your rules. As shown earlier, the validation array will have this prototype:</p> + +<code> +$config = array(<br /> + array(<br /> + 'field' => 'username', <br /> + 'label' => 'Username', <br /> + 'rules' => 'required'<br /> + ),<br /> + array(<br /> + 'field' => 'password', <br /> + 'label' => 'Password', <br /> + 'rules' => 'required'<br /> + ),<br /> + array(<br /> + 'field' => 'passconf', <br /> + 'label' => 'Password Confirmation', <br /> + 'rules' => 'required'<br /> + ), <br /> + array(<br /> + 'field' => 'email', <br /> + 'label' => 'Email', <br /> + 'rules' => 'required'<br /> + )<br /> + );<br /> +</code> + +<p><dfn>Your validation rule file will be loaded automatically and used when you call the run() function.</dfn></p> + +<p class="important">Please note that you MUST name your array $config.</p> + +<h3>Creating Sets of Rules</h3> + +<p>In order to organize your rules into "sets" requires that you place them into "sub arrays". Consider the following example, showing two sets of rules. +We've arbitrarily called these two rules "signup" and "email". You can name your rules anything you want:</p> + + +<code>$config = array(<br /> + '<kbd>signup</kbd>' => array(<br /> + array(<br /> + 'field' => 'username',<br /> + 'label' => 'Username',<br /> + 'rules' => 'required'<br /> + ),<br /> + array(<br /> + 'field' => 'password',<br /> + 'label' => 'Password',<br /> + 'rules' => 'required'<br /> + ),<br /> + array(<br /> + 'field' => 'passconf',<br /> + 'label' => 'PasswordConfirmation',<br /> + 'rules' => 'required'<br /> + ),<br /> + array(<br /> + 'field' => 'email',<br /> + 'label' => 'Email',<br /> + 'rules' => 'required'<br /> + )<br /> + ),<br /> + '<kbd>email</kbd>' => array(<br /> + array(<br /> + 'field' => 'emailaddress',<br /> + 'label' => 'EmailAddress',<br /> + 'rules' => 'required|valid_email'<br /> + ),<br /> + array(<br /> + 'field' => 'name',<br /> + 'label' => 'Name',<br /> + 'rules' => 'required|alpha'<br /> + ),<br /> + array(<br /> + 'field' => 'title',<br /> + 'label' => 'Title',<br /> + 'rules' => 'required'<br /> + ),<br /> + array(<br /> + 'field' => 'message',<br /> + 'label' => 'MessageBody',<br /> + 'rules' => 'required'<br /> + )<br /> + ) <br /> + );<br /> +</code> + + +<h3>Calling a Specific Rule Group</h3> + +<p>In order to call a specific group you will pass its name to the <kbd>run()</kbd> function. For example, to call the <kbd>signup</kbd> rule you will do this:</p> + +<code> +if ($this->form_validation->run('<kbd>signup</kbd>') == FALSE)<br /> +{<br /> + $this->load->view('myform');<br /> +}<br /> +else<br /> +{<br /> + $this->load->view('formsuccess');<br /> +}<br /> +</code> + + + +<h3>Associating a Controller Function with a Rule Group</h3> + +<p>An alternate (and more automatic) method of calling a rule group is to name it according to the controller class/function you intend to use it with. For example, let's say you +have a controller named <kbd>Member</kbd> and a function named <kbd>signup</kbd>. Here's what your class might look like:</p> + +<code> +<?php<br /><br /> +class <kbd>Member</kbd> extends Controller {<br /> +<br /> + function <kbd>signup</kbd>()<br /> + { <br /> + $this->load->library('form_validation');<br /> + <br /> + if ($this->form_validation->run() == FALSE)<br /> + {<br /> + $this->load->view('myform');<br /> + }<br /> + else<br /> + {<br /> + $this->load->view('formsuccess');<br /> + }<br /> + }<br /> +}<br /> +?></code> + +<p>In your validation config file, you will name your rule group <kbd>member/signup</kbd>:</p> + + +<code>$config = array(<br /> + '<kbd>member/signup</kbd>' = array(<br /> + array(<br /> + 'field' => 'username',<br /> + 'label' => 'Username',<br /> + 'rules' => 'required'<br /> + ),<br /> + array(<br /> + 'field' => 'password',<br /> + 'label' => 'Password',<br /> + 'rules' => 'required'<br /> + ),<br /> + array(<br /> + 'field' => 'passconf',<br /> + 'label' => 'PasswordConfirmation',<br /> + 'rules' => 'required'<br /> + ),<br /> + array(<br /> + 'field' => 'email',<br /> + 'label' => 'Email',<br /> + 'rules' => 'required'<br /> + )<br /> + )<br /> + );<br /> +</code> + +<p><dfn>When a rule group is named identically to a controller class/function it will be used automatically when the run() function is invoked from that class/function.</dfn></p> + +<p> </p> + + +<a name="arraysasfields"></a> +<h1>Using Arrays as Field Names</h1> + +<p>The Form Validation class supports the use of arrays as field names. Consider this example:</p> + +<code><input type="text" name="<kbd>options[]</kbd>" value="" size="50" /></code> + +<p>If you do use an array as a field name, you must use the EXACT array name in the <a href="#helperreference">Helper Functions</a> that require the field name, +and as your Validation Rule field name.</p> + +<p>For example, to set a rule for the above field you would use:</p> + +<code>$this->form_validation->set_rules('<kbd>options[]</kbd>', 'Options', 'required');</code> + +<p>Or, to show an error for the above field you would use:</p> + +<code><?php echo form_error('<kbd>options[]</kbd>'); ?></code> + +<p>Or to re-populate the field you would use:</p> + +<code><input type="text" name="<kbd>options[]</kbd>" value="<kbd><?php echo set_value('<kbd>options[]</kbd>'); ?></kbd>" size="50" /></code> + +<p>You can use multidimensional arrays as field names as well. For example:</p> + +<code><input type="text" name="<kbd>options[size]</kbd>" value="" size="50" /></code> + +<p>Or even:</p> + +<code><input type="text" name="<kbd>sports[nba][basketball]</kbd>" value="" size="50" /></code> + +<p>As with our first example, you must use the exact array name in the helper functions:</p> + +<code><?php echo form_error('<kbd>sports[nba][basketball]</kbd>'); ?></code> + +<p>If you are using checkboxes (or other fields) that have multiple options, don't forget to leave an empty bracket after each option, so that all selections will be added to the +POST array:</p> + +<code> +<input type="checkbox" name="<kbd>options[]</kbd>" value="red" /><br /> +<input type="checkbox" name="<kbd>options[]</kbd>" value="blue" /><br /> +<input type="checkbox" name="<kbd>options[]</kbd>" value="green" /> +</code> + +<p>Or if you use a multidimensional array:</p> + +<code> +<input type="checkbox" name="<kbd>options[color][]</kbd>" value="red" /><br /> +<input type="checkbox" name="<kbd>options[color][]</kbd>" value="blue" /><br /> +<input type="checkbox" name="<kbd>options[color][]</kbd>" value="green" /> +</code> + +<p>When you use a helper function you'll include the bracket as well:</p> + +<code><?php echo form_error('<kbd>options[color][]</kbd>'); ?></code> + + + + +<p> </p> + + +<a name="rulereference"></a> +<h1>Rule Reference</h1> + +<p>The following is a list of all the native rules that are available to use:</p> + + + +<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder"> +<tr> +<th>Rule</th> +<th>Parameter</th> +<th>Description</th> +<th>Example</th> +</tr><tr> + +<td class="td"><strong>required</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the form element is empty.</td> +<td class="td"> </td> +</tr><tr> + +<td class="td"><strong>matches</strong></td> +<td class="td">Yes</td> +<td class="td">Returns FALSE if the form element does not match the one in the parameter.</td> +<td class="td">matches[form_item]</td> +</tr><tr> + +<td class="td"><strong>min_length</strong></td> +<td class="td">Yes</td> +<td class="td">Returns FALSE if the form element is shorter then the parameter value.</td> +<td class="td">min_length[6]</td> +</tr><tr> + +<td class="td"><strong>max_length</strong></td> +<td class="td">Yes</td> +<td class="td">Returns FALSE if the form element is longer then the parameter value.</td> +<td class="td">max_length[12]</td> +</tr><tr> + +<td class="td"><strong>exact_length</strong></td> +<td class="td">Yes</td> +<td class="td">Returns FALSE if the form element is not exactly the parameter value.</td> +<td class="td">exact_length[8]</td> +</tr><tr> + +<td class="td"><strong>alpha</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the form element contains anything other than alphabetical characters.</td> +<td class="td"> </td> +</tr><tr> + +<td class="td"><strong>alpha_numeric</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the form element contains anything other than alpha-numeric characters.</td> +<td class="td"> </td> +</tr><tr> + +<td class="td"><strong>alpha_dash</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the form element contains anything other than alpha-numeric characters, underscores or dashes.</td> +<td class="td"> </td> +</tr> + +<tr> +<td class="td"><strong>numeric</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the form element contains anything other than numeric characters.</td> +<td class="td"> </td> +</tr> + +<tr> +<td class="td"><strong>integer</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the form element contains anything other than an integer.</td> +<td class="td"> </td> +</tr> + +<tr> +<td class="td"><strong>is_natural</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the form element contains anything other than a natural number: 0, 1, 2, 3, etc.</td> +<td class="td"> </td> +</tr> + +<tr> +<td class="td"><strong>is_natural_no_zero</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the form element contains anything other than a natural number, but not zero: 1, 2, 3, etc.</td> +<td class="td"> </td> +</tr> + +<tr> +<td class="td"><strong>valid_email</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the form element does not contain a valid email address.</td> +<td class="td"> </td> +</tr> + +<tr> +<td class="td"><strong>valid_emails</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if any value provided in a comma separated list is not a valid email.</td> +<td class="td"> </td> +</tr> + +<tr> +<td class="td"><strong>valid_ip</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the supplied IP is not valid.</td> +<td class="td"> </td> +</tr> + +<tr> +<td class="td"><strong>valid_base64</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the supplied string contains anything other than valid Base64 characters.</td> +<td class="td"> </td> +</tr> + + +</table> + +<p><strong>Note:</strong> These rules can also be called as discrete functions. For example:</p> + +<code>$this->form_validation->required($string);</code> + +<p class="important"><strong>Note:</strong> You can also use any native PHP functions that permit one parameter.</p> + + + +<p> </p> + +<a name="preppingreference"></a> +<h1>Prepping Reference</h1> + +<p>The following is a list of all the prepping functions that are available to use:</p> + + + +<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder"> +<tr> +<th>Name</th> +<th>Parameter</th> +<th>Description</th> +</tr><tr> + +<td class="td"><strong>xss_clean</strong></td> +<td class="td">No</td> +<td class="td">Runs the data through the XSS filtering function, described in the <a href="input.html">Input Class</a> page.</td> +</tr><tr> + +<td class="td"><strong>prep_for_form</strong></td> +<td class="td">No</td> +<td class="td">Converts special characters so that HTML data can be shown in a form field without breaking it.</td> +</tr><tr> + +<td class="td"><strong>prep_url</strong></td> +<td class="td">No</td> +<td class="td">Adds "http://" to URLs if missing.</td> +</tr><tr> + +<td class="td"><strong>strip_image_tags</strong></td> +<td class="td">No</td> +<td class="td">Strips the HTML from image tags leaving the raw URL.</td> +</tr><tr> + +<td class="td"><strong>encode_php_tags</strong></td> +<td class="td">No</td> +<td class="td">Converts PHP tags to entities.</td> +</tr> + +</table> + +<p class="important"><strong>Note:</strong> You can also use any native PHP functions that permit one parameter, +like <kbd>trim</kbd>, <kbd>htmlspecialchars</kbd>, <kbd>urldecode</kbd>, etc.</p> + + + + + + + +<p> </p> + +<a name="functionreference"></a> +<h1>Function Reference</h1> + +<p>The following functions are intended for use in your controller functions.</p> + +<h2>$this->form_validation->set_rule();</h2> + +<p>Permits you to set validation rules, as described in the tutorial sections above:</p> + +<ul> +<li><a href="#validationrules">Setting Validation Rules</a></li> +<li><a href="#savingtoconfig">Saving Groups of Validation Rules to a Config File</a></li> +</ul> + + +<h2>$this->form_validation->run();</h2> + +<p>Runs the validation routines. Returns boolean TRUE on success and FALSE on failure. You can optionally pass the name of the validation +group via the function, as described in: <a href="#savingtoconfig">Saving Groups of Validation Rules to a Config File</a>.</p> + + +<h2>$this->form_validation->set_message();</h2> + +<p>Permits you to set custom error messages. See <a href="#settingerrors">Setting Error Messages</a> above.</p> + + +<p> </p> + +<a name="helperreference"></a> +<h1>Helper Reference</h1> + +<p>The following helper functions are available for use in the view files containing your forms. Note that these are procedural functions, so they +<strong>do not</strong> require you to prepend them with $this->form_validation.</p> + +<h2>form_error()</h2> + +<p>Shows an individual error message associated with the field name supplied to the function. Example:</p> + +<code><?php echo form_error('username'); ?></code> + +<p>The error delimiters can be optionally specified. See the <a href="#errordelimiters">Changing the Error Delimiters</a> section above.</p> + + + +<h2>validation_errors()</h2> +<p>Shows all error messages as a string: Example:</p> + +<code><?php echo validation_errors(); ?></code> + +<p>The error delimiters can be optionally specified. See the <a href="#errordelimiters">Changing the Error Delimiters</a> section above.</p> + + + +<h2>set_value()</h2> + +<p>Permits you to set the value of an input form or textarea. You must supply the field name via the first parameter of the function. +The second (optional) parameter allows you to set a default value for the form. Example:</p> + +<code><input type="text" name="quantity" value="<dfn><?php echo set_value('quantity', '0'); ?></dfn>" size="50" /></code> + +<p>The above form will show "0" when loaded for the first time.</p> + +<h2>set_select()</h2> + +<p>If you use a <dfn><select></dfn> menu, this function permits you to display the menu item that was selected. The first parameter +must contain the name of the select menu, the second parameter must contain the value of +each item, and the third (optional) parameter lets you set an item as the default (use boolean TRUE/FALSE).</p> + +<p>Example:</p> + +<code> +<select name="myselect"><br /> +<option value="one" <dfn><?php echo set_select('myselect', 'one', TRUE); ?></dfn> >One</option><br /> +<option value="two" <dfn><?php echo set_select('myselect', 'two'); ?></dfn> >Two</option><br /> +<option value="three" <dfn><?php echo set_select('myselect', 'three'); ?></dfn> >Three</option><br /> +</select> +</code> + + +<h2>set_checkbox()</h2> + +<p>Permits you to display a checkbox in the state it was submitted. The first parameter +must contain the name of the checkbox, the second parameter must contain its value, and the third (optional) parameter lets you set an item as the default (use boolean TRUE/FALSE). Example:</p> + +<code><input type="checkbox" name="mycheck[]" value="1" <dfn><?php echo set_checkbox('mycheck[]', '1'); ?></dfn> /><br /> +<input type="checkbox" name="mycheck[]" value="2" <dfn><?php echo set_checkbox('mycheck[]', '2'); ?></dfn> /></code> + + +<h2>set_radio()</h2> + +<p>Permits you to display radio buttons in the state they were submitted. This function is identical to the <strong>set_checkbox()</strong> function above.</p> + +<code><input type="radio" name="myradio" value="1" <dfn><?php echo set_radio('myradio', '1', TRUE); ?></dfn> /><br /> +<input type="radio" name="myradio" value="2" <dfn><?php echo set_radio('myradio', '2'); ?></dfn> /></code> + + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="file_uploading.html">File Uploading Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="ftp.html">FTP Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/ftp.html b/user_guide/libraries/ftp.html index 1d52a290b..08a0df415 100644 --- a/user_guide/libraries/ftp.html +++ b/user_guide/libraries/ftp.html @@ -1,303 +1,303 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>FTP Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-FTP Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>FTP Class</h1>
-
-<p>CodeIgniter's FTP Class permits files to be transfered to a remote server. Remote files can also be moved, renamed,
-and deleted. The FTP class also includes a "mirroring" function that permits an entire local directory to be recreated remotely via FTP.</p>
-
-<p class="important"><strong>Note:</strong> SFTP and SSL FTP protocols are not supported, only standard FTP.</p>
-
-<h2>Initializing the Class</h2>
-
-<p>Like most other classes in CodeIgniter, the FTP class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
-
-<code>$this->load->library('ftp');</code>
-<p>Once loaded, the FTP object will be available using: <dfn>$this->ftp</dfn></p>
-
-
-<h2>Usage Examples</h2>
-
-<p>In this example a connection is opened to the FTP server, and a local file is read and uploaded in ASCII mode. The
-file permissions are set to 755. Note: Setting permissions requires PHP 5.</p>
-
-<code>
-$this->load->library('ftp');<br />
-<br />
-$config['hostname'] = 'ftp.example.com';<br />
-$config['username'] = 'your-username';<br />
-$config['password'] = 'your-password';<br />
-$config['debug'] = TRUE;<br />
-<br />
-$this->ftp->connect($config);<br />
-<br />
-$this->ftp->upload('/local/path/to/myfile.html', '/public_html/myfile.html', 'ascii', 0775);<br />
-<br />
-$this->ftp->close();
-
-</code>
-
-
-<p>In this example a list of files is retrieved from the server.</p>
-
-<code>
-$this->load->library('ftp');<br />
-<br />
-$config['hostname'] = 'ftp.example.com';<br />
-$config['username'] = 'your-username';<br />
-$config['password'] = 'your-password';<br />
-$config['debug'] = TRUE;<br />
-<br />
-$this->ftp->connect($config);<br />
-<br />
-$list = $this->ftp->list_files('/public_html/');<br />
-<br />
-print_r($list);<br />
-<br />
-$this->ftp->close();
-</code>
-
-<p>In this example a local directory is mirrored on the server.</p>
-
-
-<code>
-$this->load->library('ftp');<br />
-<br />
-$config['hostname'] = 'ftp.example.com';<br />
-$config['username'] = 'your-username';<br />
-$config['password'] = 'your-password';<br />
-$config['debug'] = TRUE;<br />
-<br />
-$this->ftp->connect($config);<br />
-<br />
-$this->ftp->mirror('/path/to/myfolder/', '/public_html/myfolder/');<br />
-<br />
-$this->ftp->close();
-</code>
-
-
-<h1>Function Reference</h1>
-
-<h2>$this->ftp->connect()</h2>
-
-<p>Connects and logs into to the FTP server. Connection preferences are set by passing an array
-to the function, or you can store them in a config file.</p>
-
-
-<p>Here is an example showing how you set preferences manually:</p>
-
-<code>
-$this->load->library('ftp');<br />
-<br />
-$config['hostname'] = 'ftp.example.com';<br />
-$config['username'] = 'your-username';<br />
-$config['password'] = 'your-password';<br />
-$config['port'] = 21;<br />
-$config['passive'] = FALSE;<br />
-$config['debug'] = TRUE;<br />
-<br />
-$this->ftp->connect($config);<br />
-</code>
-
-<h3>Setting FTP Preferences in a Config File</h3>
-
-<p>If you prefer you can store your FTP preferences in a config file.
-Simply create a new file called the <var>ftp.php</var>, add the <var>$config</var>
-array in that file. Then save the file at <var>config/ftp.php</var> and it will be used automatically.</p>
-
-<h3>Available connection options:</h3>
-
-
-<ul>
-<li><strong>hostname</strong> - the FTP hostname. Usually something like: <dfn>ftp.example.com</dfn></li>
-<li><strong>username</strong> - the FTP username.</li>
-<li><strong>password</strong> - the FTP password.</li>
-<li><strong>port</strong> - The port number. Set to <dfn>21</dfn> by default.</li>
-<li><strong>debug</strong> - <kbd>TRUE/FALSE</kbd> (boolean). Whether to enable debugging to display error messages.</li>
-<li><strong>passive</strong> - <kbd>TRUE/FALSE</kbd> (boolean). Whether to use passive mode. Passive is set automatically by default.</li>
-</ul>
-
-
-
-<h2>$this->ftp->upload()</h2>
-
-<p>Uploads a file to your server. You must supply the local path and the remote path, and you can optionally set the mode and permissions.
-Example:</p>
-
-
-<code>$this->ftp->upload('/local/path/to/myfile.html', '/public_html/myfile.html', 'ascii', 0775);</code>
-
-<p><strong>Mode options are:</strong> <kbd>ascii</kbd>, <kbd>binary</kbd>, and <kbd>auto</kbd> (the default). If
-<kbd>auto</kbd> is used it will base the mode on the file extension of the source file.</p>
-
-<p>Permissions are available if you are running PHP 5 and can be passed as an <kbd>octal</kbd> value in the fourth parameter.</p>
-
-
-<h2>$this->ftp->rename()</h2>
-<p>Permits you to rename a file. Supply the source file name/path and the new file name/path.</p>
-
-<code>
-// Renames green.html to blue.html<br />
-$this->ftp->rename('/public_html/foo/green.html', '/public_html/foo/blue.html');
-</code>
-
-<h2>$this->ftp->move()</h2>
-<p>Lets you move a file. Supply the source and destination paths:</p>
-
-<code>
-// Moves blog.html from "joe" to "fred"<br />
-$this->ftp->move('/public_html/joe/blog.html', '/public_html/fred/blog.html');
-</code>
-
-<p>Note: if the destination file name is different the file will be renamed.</p>
-
-
-<h2>$this->ftp->delete_file()</h2>
-<p>Lets you delete a file. Supply the source path with the file name.</p>
-
-<code>
-$this->ftp->delete_file('/public_html/joe/blog.html');
-</code>
-
-
-<h2>$this->ftp->delete_dir()</h2>
-<p>Lets you delete a directory and everything it contains. Supply the source path to the directory with a trailing slash.</p>
-
-<p class="important"><strong>Important</strong> Be VERY careful with this function. It will recursively delete
-<b>everything</b> within the supplied path, including sub-folders and all files. Make absolutely sure your path is correct.
-Try using the <kbd>list_files()</kbd> function first to verify that your path is correct.</p>
-
-<code>
-$this->ftp->delete_dir('/public_html/path/to/folder/');
-</code>
-
-
-
-<h2>$this->ftp->list_files()</h2>
-<p>Permits you to retrieve a list of files on your server returned as an <dfn>array</dfn>. You must supply
-the path to the desired directory.</p>
-
-<code>
-$list = $this->ftp->list_files('/public_html/');<br />
-<br />
-print_r($list);
-</code>
-
-
-<h2>$this->ftp->mirror()</h2>
-
-<p>Recursively reads a local folder and everything it contains (including sub-folders) and creates a
-mirror via FTP based on it. Whatever the directory structure of the original file path will be recreated on the server.
-You must supply a source path and a destination path:</p>
-
-<code>
-$this->ftp->mirror('/path/to/myfolder/', '/public_html/myfolder/');
-</code>
-
-
-
-<h2>$this->ftp->mkdir()</h2>
-
-<p>Lets you create a directory on your server. Supply the path ending in the folder name you wish to create, with a trailing slash.
-Permissions can be set by passed an <kbd>octal</kbd> value in the second parameter (if you are running PHP 5).</p>
-
-<code>
-// Creates a folder named "bar"<br />
-$this->ftp->mkdir('/public_html/foo/bar/', DIR_WRITE_MODE);
-</code>
-
-
-<h2>$this->ftp->chmod()</h2>
-
-<p>Permits you to set file permissions. Supply the path to the file or folder you wish to alter permissions on:</p>
-
-<code>
-// Chmod "bar" to 777<br />
-$this->ftp->chmod('/public_html/foo/bar/', DIR_WRITE_MODE);
-</code>
-
-
-
-
-<h2>$this->ftp->close();</h2>
-<p>Closes the connection to your server. It's recommended that you use this when you are finished uploading.</p>
-
-
-
-
-
-
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="form_validation.html">Form Validation Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="table.html">HTML Table Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>FTP Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +FTP Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>FTP Class</h1> + +<p>CodeIgniter's FTP Class permits files to be transfered to a remote server. Remote files can also be moved, renamed, +and deleted. The FTP class also includes a "mirroring" function that permits an entire local directory to be recreated remotely via FTP.</p> + +<p class="important"><strong>Note:</strong> SFTP and SSL FTP protocols are not supported, only standard FTP.</p> + +<h2>Initializing the Class</h2> + +<p>Like most other classes in CodeIgniter, the FTP class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p> + +<code>$this->load->library('ftp');</code> +<p>Once loaded, the FTP object will be available using: <dfn>$this->ftp</dfn></p> + + +<h2>Usage Examples</h2> + +<p>In this example a connection is opened to the FTP server, and a local file is read and uploaded in ASCII mode. The +file permissions are set to 755. Note: Setting permissions requires PHP 5.</p> + +<code> +$this->load->library('ftp');<br /> +<br /> +$config['hostname'] = 'ftp.example.com';<br /> +$config['username'] = 'your-username';<br /> +$config['password'] = 'your-password';<br /> +$config['debug'] = TRUE;<br /> +<br /> +$this->ftp->connect($config);<br /> +<br /> +$this->ftp->upload('/local/path/to/myfile.html', '/public_html/myfile.html', 'ascii', 0775);<br /> +<br /> +$this->ftp->close(); + +</code> + + +<p>In this example a list of files is retrieved from the server.</p> + +<code> +$this->load->library('ftp');<br /> +<br /> +$config['hostname'] = 'ftp.example.com';<br /> +$config['username'] = 'your-username';<br /> +$config['password'] = 'your-password';<br /> +$config['debug'] = TRUE;<br /> +<br /> +$this->ftp->connect($config);<br /> +<br /> +$list = $this->ftp->list_files('/public_html/');<br /> +<br /> +print_r($list);<br /> +<br /> +$this->ftp->close(); +</code> + +<p>In this example a local directory is mirrored on the server.</p> + + +<code> +$this->load->library('ftp');<br /> +<br /> +$config['hostname'] = 'ftp.example.com';<br /> +$config['username'] = 'your-username';<br /> +$config['password'] = 'your-password';<br /> +$config['debug'] = TRUE;<br /> +<br /> +$this->ftp->connect($config);<br /> +<br /> +$this->ftp->mirror('/path/to/myfolder/', '/public_html/myfolder/');<br /> +<br /> +$this->ftp->close(); +</code> + + +<h1>Function Reference</h1> + +<h2>$this->ftp->connect()</h2> + +<p>Connects and logs into to the FTP server. Connection preferences are set by passing an array +to the function, or you can store them in a config file.</p> + + +<p>Here is an example showing how you set preferences manually:</p> + +<code> +$this->load->library('ftp');<br /> +<br /> +$config['hostname'] = 'ftp.example.com';<br /> +$config['username'] = 'your-username';<br /> +$config['password'] = 'your-password';<br /> +$config['port'] = 21;<br /> +$config['passive'] = FALSE;<br /> +$config['debug'] = TRUE;<br /> +<br /> +$this->ftp->connect($config);<br /> +</code> + +<h3>Setting FTP Preferences in a Config File</h3> + +<p>If you prefer you can store your FTP preferences in a config file. +Simply create a new file called the <var>ftp.php</var>, add the <var>$config</var> +array in that file. Then save the file at <var>config/ftp.php</var> and it will be used automatically.</p> + +<h3>Available connection options:</h3> + + +<ul> +<li><strong>hostname</strong> - the FTP hostname. Usually something like: <dfn>ftp.example.com</dfn></li> +<li><strong>username</strong> - the FTP username.</li> +<li><strong>password</strong> - the FTP password.</li> +<li><strong>port</strong> - The port number. Set to <dfn>21</dfn> by default.</li> +<li><strong>debug</strong> - <kbd>TRUE/FALSE</kbd> (boolean). Whether to enable debugging to display error messages.</li> +<li><strong>passive</strong> - <kbd>TRUE/FALSE</kbd> (boolean). Whether to use passive mode. Passive is set automatically by default.</li> +</ul> + + + +<h2>$this->ftp->upload()</h2> + +<p>Uploads a file to your server. You must supply the local path and the remote path, and you can optionally set the mode and permissions. +Example:</p> + + +<code>$this->ftp->upload('/local/path/to/myfile.html', '/public_html/myfile.html', 'ascii', 0775);</code> + +<p><strong>Mode options are:</strong> <kbd>ascii</kbd>, <kbd>binary</kbd>, and <kbd>auto</kbd> (the default). If +<kbd>auto</kbd> is used it will base the mode on the file extension of the source file.</p> + +<p>Permissions are available if you are running PHP 5 and can be passed as an <kbd>octal</kbd> value in the fourth parameter.</p> + + +<h2>$this->ftp->rename()</h2> +<p>Permits you to rename a file. Supply the source file name/path and the new file name/path.</p> + +<code> +// Renames green.html to blue.html<br /> +$this->ftp->rename('/public_html/foo/green.html', '/public_html/foo/blue.html'); +</code> + +<h2>$this->ftp->move()</h2> +<p>Lets you move a file. Supply the source and destination paths:</p> + +<code> +// Moves blog.html from "joe" to "fred"<br /> +$this->ftp->move('/public_html/joe/blog.html', '/public_html/fred/blog.html'); +</code> + +<p>Note: if the destination file name is different the file will be renamed.</p> + + +<h2>$this->ftp->delete_file()</h2> +<p>Lets you delete a file. Supply the source path with the file name.</p> + +<code> +$this->ftp->delete_file('/public_html/joe/blog.html'); +</code> + + +<h2>$this->ftp->delete_dir()</h2> +<p>Lets you delete a directory and everything it contains. Supply the source path to the directory with a trailing slash.</p> + +<p class="important"><strong>Important</strong> Be VERY careful with this function. It will recursively delete +<b>everything</b> within the supplied path, including sub-folders and all files. Make absolutely sure your path is correct. +Try using the <kbd>list_files()</kbd> function first to verify that your path is correct.</p> + +<code> +$this->ftp->delete_dir('/public_html/path/to/folder/'); +</code> + + + +<h2>$this->ftp->list_files()</h2> +<p>Permits you to retrieve a list of files on your server returned as an <dfn>array</dfn>. You must supply +the path to the desired directory.</p> + +<code> +$list = $this->ftp->list_files('/public_html/');<br /> +<br /> +print_r($list); +</code> + + +<h2>$this->ftp->mirror()</h2> + +<p>Recursively reads a local folder and everything it contains (including sub-folders) and creates a +mirror via FTP based on it. Whatever the directory structure of the original file path will be recreated on the server. +You must supply a source path and a destination path:</p> + +<code> +$this->ftp->mirror('/path/to/myfolder/', '/public_html/myfolder/'); +</code> + + + +<h2>$this->ftp->mkdir()</h2> + +<p>Lets you create a directory on your server. Supply the path ending in the folder name you wish to create, with a trailing slash. +Permissions can be set by passed an <kbd>octal</kbd> value in the second parameter (if you are running PHP 5).</p> + +<code> +// Creates a folder named "bar"<br /> +$this->ftp->mkdir('/public_html/foo/bar/', DIR_WRITE_MODE); +</code> + + +<h2>$this->ftp->chmod()</h2> + +<p>Permits you to set file permissions. Supply the path to the file or folder you wish to alter permissions on:</p> + +<code> +// Chmod "bar" to 777<br /> +$this->ftp->chmod('/public_html/foo/bar/', DIR_WRITE_MODE); +</code> + + + + +<h2>$this->ftp->close();</h2> +<p>Closes the connection to your server. It's recommended that you use this when you are finished uploading.</p> + + + + + + + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="form_validation.html">Form Validation Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="table.html">HTML Table Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/image_lib.html b/user_guide/libraries/image_lib.html index 1bbb842cc..3d4278914 100644 --- a/user_guide/libraries/image_lib.html +++ b/user_guide/libraries/image_lib.html @@ -1,666 +1,666 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Image Manipulation Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Image Manipulation Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>Image Manipulation Class</h1>
-
-<p>CodeIgniter's Image Manipulation class lets you perform the following actions:</p>
-
-<ul>
-<li>Image Resizing</li>
-<li>Thumbnail Creation</li>
-<li>Image Cropping</li>
-<li>Image Rotating</li>
-<li>Image Watermarking</li>
-</ul>
-
-<p>All three major image libraries are supported: GD/GD2, NetPBM, and ImageMagick</p>
-
-<p class="important"><strong>Note:</strong> Watermarking is only available using the GD/GD2 library.
-In addition, even though other libraries are supported, GD is required in
-order for the script to calculate the image properties. The image processing, however, will be performed with the
-library you specify.</p>
-
-
-<h2>Initializing the Class</h2>
-
-<p>Like most other classes in CodeIgniter, the image class is initialized in your controller
-using the <dfn>$this->load->library</dfn> function:</p>
-<code>$this->load->library('image_lib');</code>
-
-<p>Once the library is loaded it will be ready for use. The image library object you will use to call all functions is: <dfn>$this->image_lib</dfn></p>
-
-
-<h2>Processing an Image</h2>
-
-<p>Regardless of the type of processing you would like to perform (resizing, cropping, rotation, or watermarking), the general process is
-identical. You will set some preferences corresponding to the action you intend to perform, then
-call one of four available processing functions. For example, to create an image thumbnail you'll do this:</p>
-
-<code>$config['image_library'] = 'gd2';<br />
-$config['source_image'] = '/path/to/image/mypic.jpg';<br />
-$config['create_thumb'] = TRUE;<br />
-$config['maintain_ratio'] = TRUE;<br />
-$config['width'] = 75;<br />
-$config['height'] = 50;<br />
-<br />
-$this->load->library('image_lib', $config);
-<br />
-<br />
-$this->image_lib->resize();</code>
-
-<p>The above code tells the <dfn>image_resize</dfn> function to look for an image called <em>mypic.jpg</em>
-located in the <dfn>source_image</dfn> folder, then create a thumbnail that is 75 X 50 pixels using the GD2 <dfn>image_library</dfn>.
-Since the <dfn>maintain_ratio</dfn> option is enabled, the thumb will be as close to the target <dfn>width</dfn> and
-<dfn>height</dfn> as possible while preserving the original aspect ratio. The thumbnail will be called <em>mypic_thumb.jpg</em>
-</p>
-
-<p class="important"><strong>Note:</strong> In order for the image class to be allowed to do any processing, the
-folder containing the image files must have write permissions.</p>
-
-
-<h2>Processing Functions</h2>
-
-<p>There are four available processing functions:</p>
-
-<ul>
-<li>$this->image_lib->resize()</li>
-<li>$this->image_lib->crop()</li>
-<li>$this->image_lib->rotate()</li>
-<li>$this->image_lib->watermark()</li>
-<li>$this->image_lib->clear()</li>
-</ul>
-
-<p>These functions return boolean TRUE upon success and FALSE for failure. If they fail you can retrieve the
-error message using this function:</p>
-
-<code>echo $this->image_lib->display_errors();</code>
-
-<p>A good practice is use the processing function conditionally, showing an error upon failure, like this:</p>
-
-<code>if ( ! $this->image_lib->resize())<br />
-{<br />
- echo $this->image_lib->display_errors();<br />
-}</code>
-
-<p>Note: You can optionally specify the HTML formatting to be applied to the errors, by submitting the opening/closing
-tags in the function, like this:</p>
-
-<code>$this->image_lib->display_errors('<var><p></var>', '<var></p></var>');</code>
-
-
-<h2>Preferences</h2>
-
-<p>The preferences described below allow you to tailor the image processing to suit your needs.</p>
-
-<p>Note that not all preferences are available for every
-function. For example, the x/y axis preferences are only available for image cropping. Likewise, the width and height
-preferences have no effect on cropping. The "availability" column indicates which functions support a given preference.</p>
-
-<p>Availability Legend:</p>
-
-<ul>
-<li><var>R</var> - Image Resizing</li>
-<li><var>C</var> - Image Cropping</li>
-<li><var>X</var> - Image Rotation</li>
-<li><var>W</var> - Image Watermarking</li>
-
-</ul>
-
-
-
-
-
-<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
-<tr>
-<th>Preference</th>
-<th>Default Value</th>
-<th>Options</th>
-<th>Description</th>
-<th>Availability</th>
-</tr>
-
-<tr>
-<td class="td"><strong>image_library</strong></td>
-<td class="td">GD2</td>
-<td class="td">GD, GD2, ImageMagick, NetPBM</td>
-<td class="td">Sets the image library to be used.</td>
-<td class="td">R, C, X, W</td>
-</tr>
-
-<tr>
-<td class="td"><strong>library_path</strong></td>
-<td class="td">None</td>
-<td class="td">None</td>
-<td class="td">Sets the server path to your ImageMagick or NetPBM library. If you use either of those libraries you must supply the path.</td>
-<td class="td">R, C, X</td>
-</tr>
-
-<tr>
-<td class="td"><strong>source_image</strong></td>
-<td class="td">None</td>
-<td class="td">None</td>
-<td class="td">Sets the source image name/path. The path must be a relative or absolute server path, not a URL.</td>
-<td class="td">R, C, S, W</td>
-</tr>
-
-<tr>
-<td class="td"><strong>dynamic_output</strong></td>
-<td class="td">FALSE</td>
-<td class="td">TRUE/FALSE (boolean)</td>
-<td class="td">Determines whether the new image file should be written to disk or generated dynamically. Note: If you choose the dynamic setting, only one image can be shown at a time, and it can't be positioned on the page. It simply outputs the raw image dynamically to your browser, along with image headers.</td>
-<td class="td">R, C, X, W</td>
-</tr>
-
-
-<tr>
-<td class="td"><strong>quality</strong></td>
-<td class="td">90%</td>
-<td class="td">1 - 100%</td>
-<td class="td">Sets the quality of the image. The higher the quality the larger the file size.</td>
-<td class="td">R, C, X, W</td>
-</tr>
-
-
-<tr>
-<td class="td"><strong>new_image</strong></td>
-<td class="td">None</td>
-<td class="td">None</td>
-<td class="td">Sets the destination image name/path. You'll use this preference when creating an image copy. The path must be a relative or absolute server path, not a URL.</td>
-<td class="td">R, C, X, W</td>
-</tr>
-
-<tr>
-<td class="td"><strong>width</strong></td>
-<td class="td">None</td>
-<td class="td">None</td>
-<td class="td">Sets the width you would like the image set to.</td>
-<td class="td">R, C </td>
-</tr>
-
-<tr>
-<td class="td"><strong>height</strong></td>
-<td class="td">None</td>
-<td class="td">None</td>
-<td class="td">Sets the height you would like the image set to.</td>
-<td class="td">R, C </td>
-</tr>
-
-<tr>
-<td class="td"><strong>create_thumb</strong></td>
-<td class="td">FALSE</td>
-<td class="td">TRUE/FALSE (boolean)</td>
-<td class="td">Tells the image processing function to create a thumb.</td>
-<td class="td">R</td>
-</tr>
-
-<tr>
-<td class="td"><strong>thumb_marker</strong></td>
-<td class="td">_thumb</td>
-<td class="td">None</td>
-<td class="td">Specifies the thumbnail indicator. It will be inserted just before the file extension, so mypic.jpg would become mypic_thumb.jpg</td>
-<td class="td">R</td>
-</tr>
-
-<tr>
-<td class="td"><strong>maintain_ratio</strong></td>
-<td class="td">TRUE</td>
-<td class="td">TRUE/FALSE (boolean)</td>
-<td class="td">Specifies whether to maintain the original aspect ratio when resizing or use hard values.</td>
-<td class="td">R, C</td>
-</tr>
-
-
-<tr>
-<td class="td"><strong>master_dim</strong></td>
-<td class="td">auto</td>
-<td class="td">auto, width, height</td>
-<td class="td">Specifies what to use as the master axis when resizing or creating thumbs. For example, let's say you want to resize an image to 100 X 75 pixels. If the source image size does not allow perfect resizing to those dimensions, this setting determines which axis should be used as the hard value. "auto" sets the axis automatically based on whether the image is taller then wider, or vice versa.</td>
-<td class="td">R</td>
-</tr>
-
-
-
-
-<tr>
-<td class="td"><strong>rotation_angle</strong></td>
-<td class="td">None</td>
-<td class="td">90, 180, 270, vrt, hor</td>
-<td class="td">Specifies the angle of rotation when rotating images. Note that PHP rotates counter-clockwise, so a 90 degree rotation to the right must be specified as 270.</td>
-<td class="td">X</td>
-</tr>
-
-<tr>
-<td class="td"><strong>x_axis</strong></td>
-<td class="td">None</td>
-<td class="td">None</td>
-<td class="td">Sets the X coordinate in pixels for image cropping. For example, a setting of 30 will crop an image 30 pixels from the left.</td>
-<td class="td">C</td>
-</tr>
-<tr>
-<td class="td"><strong>y_axis</strong></td>
-<td class="td">None</td>
-<td class="td">None</td>
-<td class="td">Sets the Y coordinate in pixels for image cropping. For example, a setting of 30 will crop an image 30 pixels from the top.</td>
-<td class="td">C</td>
-</tr>
-
-</table>
-
-
-<h2>Setting preferences in a config file</h2>
-
-<p>If you prefer not to set preferences using the above method, you can instead put them into a config file.
-Simply create a new file called <var>image_lib.php</var>, add the <var>$config</var>
-array in that file. Then save the file in: <var>config/image_lib.php</var> and it will be used automatically. You
-will NOT need to use the <dfn>$this->image_lib->initialize</dfn> function if you save your preferences in a config file.</p>
-
-
-<h2>$this->image_lib->resize()</h2>
-
-<p>The image resizing function lets you resize the original image, create a copy (with or without resizing),
-or create a thumbnail image.</p>
-
-<p>For practical purposes there is no difference between creating a copy and creating
-a thumbnail except a thumb will have the thumbnail marker as part of the name (ie, mypic_thumb.jpg).</p>
-
-<p>All preferences listed in the table above are available for this function except these three: rotation_angle, x_axis, and y_axis.</p>
-
-<h3>Creating a Thumbnail</h3>
-
-<p>The resizing function will create a thumbnail file (and preserve the original) if you set this preference to TRUE:</p>
-
-<code>$config['create_thumb'] = TRUE;</code>
-
-<p>This single preference determines whether a thumbnail is created or not.</p>
-
-<h3>Creating a Copy</h3>
-
-<p>The resizing function will create a copy of the image file (and preserve the original) if you set
-a path and/or a new filename using this preference:</p>
-
-<code>$config['new_image'] = '/path/to/new_image.jpg';</code>
-
-<p>Notes regarding this preference:</p>
-<ul>
-<li>If only the new image name is specified it will be placed in the same folder as the original</li>
-<li>If only the path is specified, the new image will be placed in the destination with the same name as the original.</li>
-<li>If both the path and image name are specified it will placed in its own destination and given the new name.</li>
-</ul>
-
-
-<h3>Resizing the Original Image</h3>
-
-<p>If neither of the two preferences listed above (create_thumb, and new_image) are used, the resizing function will instead
-target the original image for processing.</p>
-
-
-<h2>$this->image_lib->crop()</h2>
-
-<p>The cropping function works nearly identically to the resizing function except it requires that you set
-preferences for the X and Y axis (in pixels) specifying where to crop, like this:</p>
-
-<code>$config['x_axis'] = '100';<br />
-$config['y_axis'] = '40';</code>
-
-<p>All preferences listed in the table above are available for this function except these: rotation_angle, width, height, create_thumb, new_image.</p>
-
-<p>Here's an example showing how you might crop an image:</p>
-
-<code>$config['image_library'] = 'imagemagick';<br />
-$config['library_path'] = '/usr/X11R6/bin/';<br />
-$config['source_image'] = '/path/to/image/mypic.jpg';<br />
-$config['x_axis'] = '100';<br />
-$config['y_axis'] = '60';<br />
-<br />
-$this->image_lib->initialize($config);
-<br />
-<br />
-if ( ! $this->image_lib->crop())<br />
-{<br />
- echo $this->image_lib->display_errors();<br />
-}</code>
-
-
-<p>Note: Without a visual interface it is difficult to crop images, so this function is not very useful
-unless you intend to build such an interface. That's exactly what we did using for the photo
-gallery module in ExpressionEngine, the CMS we develop. We added a JavaScript UI that lets the cropping
-area be selected.</p>
-
-<h2>$this->image_lib->rotate()</h2>
-
-<p>The image rotation function requires that the angle of rotation be set via its preference:</p>
-
-<code>$config['rotation_angle'] = '90';</code>
-
-<p>There are 5 rotation options:</p>
-
-<ol>
-<li>90 - rotates counter-clockwise by 90 degrees.</li>
-<li>180 - rotates counter-clockwise by 180 degrees.</li>
-<li>270 - rotates counter-clockwise by 270 degrees.</li>
-<li>hor - flips the image horizontally.</li>
-<li>vrt - flips the image vertically.</li>
-</ol>
-
-<p>Here's an example showing how you might rotate an image:</p>
-
-<code>$config['image_library'] = 'netpbm';<br />
-$config['library_path'] = '/usr/bin/';<br />
-$config['source_image'] = '/path/to/image/mypic.jpg';<br />
-$config['rotation_angle'] = 'hor';<br />
-<br />
-$this->image_lib->initialize($config);
-<br />
-<br />
-if ( ! $this->image_lib->rotate())<br />
-{<br />
- echo $this->image_lib->display_errors();<br />
-}</code>
-
-
-
-<h2>$this->image_lib->clear()</h2>
-<p>The clear function resets all of the values used when processing an image. You will want to call this if you are processing images in a loop.</p>
-<p><code>$this->image_lib->clear();</code></p>
-<p> </p>
-<h1>Image Watermarking</h1>
-
-<p>The Watermarking feature requires the GD/GD2 library.</p>
-
-
-<h2>Two Types of Watermarking</h2>
-
-<p>There are two types of watermarking that you can use:</p>
-
-<ul>
-<li><strong>Text</strong>: The watermark message will be generating using text, either with a True Type font that you specify, or
-using the native text output that the GD library supports. If you use the True Type version your GD installation
-must be compiled with True Type support (most are, but not all).</li>
-
-<li><strong>Overlay</strong>: The watermark message will be generated by overlaying an image (usually a transparent PNG or GIF)
-containing your watermark over the source image.</li>
-
-</ul>
-
-
-<h2>Watermarking an Image</h2>
-
-<p>Just as with the other functions (resizing, cropping, and rotating) the general process for watermarking
-involves setting the preferences corresponding to the action you intend to perform, then
-calling the watermark function. Here is an example:</p>
-
-<code>
-$config['source_image'] = '/path/to/image/mypic.jpg';<br />
-$config['wm_text'] = 'Copyright 2006 - John Doe';<br />
-$config['wm_type'] = 'text';<br />
-$config['wm_font_path'] = './system/fonts/texb.ttf';<br />
-$config['wm_font_size'] = '16';<br />
-$config['wm_font_color'] = 'ffffff';<br />
-$config['wm_vrt_alignment'] = 'bottom';<br />
-$config['wm_hor_alignment'] = 'center';<br />
-$config['wm_padding'] = '20';<br />
-<br />
-$this->image_lib->initialize($config);
-<br />
-<br />
-$this->image_lib->watermark();</code>
-
-
-<p>The above example will use a 16 pixel True Type font to create the text "Copyright 2006 - John Doe". The watermark
-will be positioned at the bottom/center of the image, 20 pixels from the bottom of the image.</p>
-
-<p class="important"><strong>Note:</strong> In order for the image class to be allowed to do any processing, the image file must have "write" file permissions. For example, 777.</p>
-
-
-<h2>Watermarking Preferences</h2>
-
-<p>This table shown the preferences that are available for both types of watermarking (text or overlay)</p>
-
-<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
-<tr>
-<th>Preference</th>
-<th>Default Value</th>
-<th>Options</th>
-<th>Description</th>
-</tr>
-
-<tr>
-<td class="td"><strong>wm_type</strong></td>
-<td class="td">text</td>
-<td class="td">text, overlay</td>
-<td class="td">Sets the type of watermarking that should be used.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>source_image</strong></td>
-<td class="td">None</td>
-<td class="td">None</td>
-<td class="td">Sets the source image name/path. The path must be a relative or absolute server path, not a URL.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>dynamic_output</strong></td>
-<td class="td">FALSE</td>
-<td class="td">TRUE/FALSE (boolean)</td>
-<td class="td">Determines whether the new image file should be written to disk or generated dynamically. Note: If you choose the dynamic setting, only one image can be shown at a time, and it can't be positioned on the page. It simply outputs the raw image dynamically to your browser, along with image headers.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>quality</strong></td>
-<td class="td">90%</td>
-<td class="td">1 - 100%</td>
-<td class="td">Sets the quality of the image. The higher the quality the larger the file size.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>padding</strong></td>
-<td class="td">None</td>
-<td class="td">A number</td>
-<td class="td">The amount of padding, set in pixels, that will be applied to the watermark to set it away from the edge of your images.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>wm_vrt_alignment</strong></td>
-<td class="td">bottom</td>
-<td class="td">top, middle, bottom</td>
-<td class="td">Sets the vertical alignment for the watermark image.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>wm_hor_alignment</strong></td>
-<td class="td">center</td>
-<td class="td">left, center, right</td>
-<td class="td">Sets the horizontal alignment for the watermark image.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>wm_hor_offset</strong></td>
-<td class="td">None</td>
-<td class="td">None</td>
-<td class="td">You may specify a horizontal offset (in pixels) to apply to the watermark position. The offset normally moves the watermark to the right, except if you have your alignment set to "right" then your offset value will move the watermark toward the left of the image.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>wm_vrt_offset</strong></td>
-<td class="td">None</td>
-<td class="td">None</td>
-<td class="td">You may specify a vertical offset (in pixels) to apply to the watermark position. The offset normally moves the watermark down, except if you have your alignment set to "bottom" then your offset value will move the watermark toward the top of the image.</td>
-</tr>
-
-</table>
-
-
-
-<h3>Text Preferences</h3>
-<p>This table shown the preferences that are available for the text type of watermarking.</p>
-
-
-<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
-<tr>
-<th>Preference</th>
-<th>Default Value</th>
-<th>Options</th>
-<th>Description</th>
-</tr>
-
-<tr>
-<td class="td"><strong>wm_text</strong></td>
-<td class="td">None</td>
-<td class="td">None</td>
-<td class="td">The text you would like shown as the watermark. Typically this will be a copyright notice.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>wm_font_path</strong></td>
-<td class="td">None</td>
-<td class="td">None</td>
-<td class="td">The server path to the True Type Font you would like to use. If you do not use this option, the native GD font will be used.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>wm_font_size</strong></td>
-<td class="td">16</td>
-<td class="td">None</td>
-<td class="td">The size of the text. Note: If you are not using the True Type option above, the number is set using a range of 1 - 5. Otherwise, you can use any valid pixel size for the font you're using.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>wm_font_color</strong></td>
-<td class="td">ffffff</td>
-<td class="td">None</td>
-<td class="td">The font color, specified in hex. Note, you must use the full 6 character hex value (ie, 993300), rather than the three character abbreviated version (ie fff).</td>
-</tr>
-
-
-<tr>
-<td class="td"><strong>wm_shadow_color</strong></td>
-<td class="td">None</td>
-<td class="td">None</td>
-<td class="td">The color of the drop shadow, specified in hex. If you leave this blank a drop shadow will not be used. Note, you must use the full 6 character hex value (ie, 993300), rather than the three character abbreviated version (ie fff).</td>
-</tr>
-
-<tr>
-<td class="td"><strong>wm_shadow_distance</strong></td>
-<td class="td">3</td>
-<td class="td">None</td>
-<td class="td">The distance (in pixels) from the font that the drop shadow should appear.</td>
-</tr>
-
-</table>
-
-
-
-
-<h3>Overlay Preferences</h3>
-<p>This table shown the preferences that are available for the overlay type of watermarking.</p>
-
-
-<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
-<tr>
-<th>Preference</th>
-<th>Default Value</th>
-<th>Options</th>
-<th>Description</th>
-</tr>
-
-<tr>
-<td class="td"><strong>wm_overlay_path</strong></td>
-<td class="td">None</td>
-<td class="td">None</td>
-<td class="td">The server path to the image you wish to use as your watermark. Required only if you are using the overlay method.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>wm_opacity</strong></td>
-<td class="td">50</td>
-<td class="td">1 - 100</td>
-<td class="td">Image opacity. You may specify the opacity (i.e. transparency) of your watermark image. This allows the watermark to be faint and not completely obscure the details from the original image behind it. A 50% opacity is typical.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>wm_x_transp</strong></td>
-<td class="td">4</td>
-<td class="td">A number</td>
-<td class="td">If your watermark image is a PNG or GIF image, you may specify a color on the image to be "transparent". This setting (along with the next) will allow you to specify that color. This works by specifying the "X" and "Y" coordinate pixel (measured from the upper left) within the image that corresponds to a pixel representative of the color you want to be transparent.</td>
-</tr>
-
-<tr>
-<td class="td"><strong>wm_y_transp</strong></td>
-<td class="td">4</td>
-<td class="td">A number</td>
-<td class="td">Along with the previous setting, this allows you to specify the coordinate to a pixel representative of the color you want to be transparent.</td>
-</tr>
-</table>
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="table.html">HTML Table Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="input.html">Input Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Image Manipulation Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Image Manipulation Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>Image Manipulation Class</h1> + +<p>CodeIgniter's Image Manipulation class lets you perform the following actions:</p> + +<ul> +<li>Image Resizing</li> +<li>Thumbnail Creation</li> +<li>Image Cropping</li> +<li>Image Rotating</li> +<li>Image Watermarking</li> +</ul> + +<p>All three major image libraries are supported: GD/GD2, NetPBM, and ImageMagick</p> + +<p class="important"><strong>Note:</strong> Watermarking is only available using the GD/GD2 library. +In addition, even though other libraries are supported, GD is required in +order for the script to calculate the image properties. The image processing, however, will be performed with the +library you specify.</p> + + +<h2>Initializing the Class</h2> + +<p>Like most other classes in CodeIgniter, the image class is initialized in your controller +using the <dfn>$this->load->library</dfn> function:</p> +<code>$this->load->library('image_lib');</code> + +<p>Once the library is loaded it will be ready for use. The image library object you will use to call all functions is: <dfn>$this->image_lib</dfn></p> + + +<h2>Processing an Image</h2> + +<p>Regardless of the type of processing you would like to perform (resizing, cropping, rotation, or watermarking), the general process is +identical. You will set some preferences corresponding to the action you intend to perform, then +call one of four available processing functions. For example, to create an image thumbnail you'll do this:</p> + +<code>$config['image_library'] = 'gd2';<br /> +$config['source_image'] = '/path/to/image/mypic.jpg';<br /> +$config['create_thumb'] = TRUE;<br /> +$config['maintain_ratio'] = TRUE;<br /> +$config['width'] = 75;<br /> +$config['height'] = 50;<br /> +<br /> +$this->load->library('image_lib', $config); +<br /> +<br /> +$this->image_lib->resize();</code> + +<p>The above code tells the <dfn>image_resize</dfn> function to look for an image called <em>mypic.jpg</em> +located in the <dfn>source_image</dfn> folder, then create a thumbnail that is 75 X 50 pixels using the GD2 <dfn>image_library</dfn>. +Since the <dfn>maintain_ratio</dfn> option is enabled, the thumb will be as close to the target <dfn>width</dfn> and +<dfn>height</dfn> as possible while preserving the original aspect ratio. The thumbnail will be called <em>mypic_thumb.jpg</em> +</p> + +<p class="important"><strong>Note:</strong> In order for the image class to be allowed to do any processing, the +folder containing the image files must have write permissions.</p> + + +<h2>Processing Functions</h2> + +<p>There are four available processing functions:</p> + +<ul> +<li>$this->image_lib->resize()</li> +<li>$this->image_lib->crop()</li> +<li>$this->image_lib->rotate()</li> +<li>$this->image_lib->watermark()</li> +<li>$this->image_lib->clear()</li> +</ul> + +<p>These functions return boolean TRUE upon success and FALSE for failure. If they fail you can retrieve the +error message using this function:</p> + +<code>echo $this->image_lib->display_errors();</code> + +<p>A good practice is use the processing function conditionally, showing an error upon failure, like this:</p> + +<code>if ( ! $this->image_lib->resize())<br /> +{<br /> + echo $this->image_lib->display_errors();<br /> +}</code> + +<p>Note: You can optionally specify the HTML formatting to be applied to the errors, by submitting the opening/closing +tags in the function, like this:</p> + +<code>$this->image_lib->display_errors('<var><p></var>', '<var></p></var>');</code> + + +<h2>Preferences</h2> + +<p>The preferences described below allow you to tailor the image processing to suit your needs.</p> + +<p>Note that not all preferences are available for every +function. For example, the x/y axis preferences are only available for image cropping. Likewise, the width and height +preferences have no effect on cropping. The "availability" column indicates which functions support a given preference.</p> + +<p>Availability Legend:</p> + +<ul> +<li><var>R</var> - Image Resizing</li> +<li><var>C</var> - Image Cropping</li> +<li><var>X</var> - Image Rotation</li> +<li><var>W</var> - Image Watermarking</li> + +</ul> + + + + + +<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder"> +<tr> +<th>Preference</th> +<th>Default Value</th> +<th>Options</th> +<th>Description</th> +<th>Availability</th> +</tr> + +<tr> +<td class="td"><strong>image_library</strong></td> +<td class="td">GD2</td> +<td class="td">GD, GD2, ImageMagick, NetPBM</td> +<td class="td">Sets the image library to be used.</td> +<td class="td">R, C, X, W</td> +</tr> + +<tr> +<td class="td"><strong>library_path</strong></td> +<td class="td">None</td> +<td class="td">None</td> +<td class="td">Sets the server path to your ImageMagick or NetPBM library. If you use either of those libraries you must supply the path.</td> +<td class="td">R, C, X</td> +</tr> + +<tr> +<td class="td"><strong>source_image</strong></td> +<td class="td">None</td> +<td class="td">None</td> +<td class="td">Sets the source image name/path. The path must be a relative or absolute server path, not a URL.</td> +<td class="td">R, C, S, W</td> +</tr> + +<tr> +<td class="td"><strong>dynamic_output</strong></td> +<td class="td">FALSE</td> +<td class="td">TRUE/FALSE (boolean)</td> +<td class="td">Determines whether the new image file should be written to disk or generated dynamically. Note: If you choose the dynamic setting, only one image can be shown at a time, and it can't be positioned on the page. It simply outputs the raw image dynamically to your browser, along with image headers.</td> +<td class="td">R, C, X, W</td> +</tr> + + +<tr> +<td class="td"><strong>quality</strong></td> +<td class="td">90%</td> +<td class="td">1 - 100%</td> +<td class="td">Sets the quality of the image. The higher the quality the larger the file size.</td> +<td class="td">R, C, X, W</td> +</tr> + + +<tr> +<td class="td"><strong>new_image</strong></td> +<td class="td">None</td> +<td class="td">None</td> +<td class="td">Sets the destination image name/path. You'll use this preference when creating an image copy. The path must be a relative or absolute server path, not a URL.</td> +<td class="td">R, C, X, W</td> +</tr> + +<tr> +<td class="td"><strong>width</strong></td> +<td class="td">None</td> +<td class="td">None</td> +<td class="td">Sets the width you would like the image set to.</td> +<td class="td">R, C </td> +</tr> + +<tr> +<td class="td"><strong>height</strong></td> +<td class="td">None</td> +<td class="td">None</td> +<td class="td">Sets the height you would like the image set to.</td> +<td class="td">R, C </td> +</tr> + +<tr> +<td class="td"><strong>create_thumb</strong></td> +<td class="td">FALSE</td> +<td class="td">TRUE/FALSE (boolean)</td> +<td class="td">Tells the image processing function to create a thumb.</td> +<td class="td">R</td> +</tr> + +<tr> +<td class="td"><strong>thumb_marker</strong></td> +<td class="td">_thumb</td> +<td class="td">None</td> +<td class="td">Specifies the thumbnail indicator. It will be inserted just before the file extension, so mypic.jpg would become mypic_thumb.jpg</td> +<td class="td">R</td> +</tr> + +<tr> +<td class="td"><strong>maintain_ratio</strong></td> +<td class="td">TRUE</td> +<td class="td">TRUE/FALSE (boolean)</td> +<td class="td">Specifies whether to maintain the original aspect ratio when resizing or use hard values.</td> +<td class="td">R, C</td> +</tr> + + +<tr> +<td class="td"><strong>master_dim</strong></td> +<td class="td">auto</td> +<td class="td">auto, width, height</td> +<td class="td">Specifies what to use as the master axis when resizing or creating thumbs. For example, let's say you want to resize an image to 100 X 75 pixels. If the source image size does not allow perfect resizing to those dimensions, this setting determines which axis should be used as the hard value. "auto" sets the axis automatically based on whether the image is taller then wider, or vice versa.</td> +<td class="td">R</td> +</tr> + + + + +<tr> +<td class="td"><strong>rotation_angle</strong></td> +<td class="td">None</td> +<td class="td">90, 180, 270, vrt, hor</td> +<td class="td">Specifies the angle of rotation when rotating images. Note that PHP rotates counter-clockwise, so a 90 degree rotation to the right must be specified as 270.</td> +<td class="td">X</td> +</tr> + +<tr> +<td class="td"><strong>x_axis</strong></td> +<td class="td">None</td> +<td class="td">None</td> +<td class="td">Sets the X coordinate in pixels for image cropping. For example, a setting of 30 will crop an image 30 pixels from the left.</td> +<td class="td">C</td> +</tr> +<tr> +<td class="td"><strong>y_axis</strong></td> +<td class="td">None</td> +<td class="td">None</td> +<td class="td">Sets the Y coordinate in pixels for image cropping. For example, a setting of 30 will crop an image 30 pixels from the top.</td> +<td class="td">C</td> +</tr> + +</table> + + +<h2>Setting preferences in a config file</h2> + +<p>If you prefer not to set preferences using the above method, you can instead put them into a config file. +Simply create a new file called <var>image_lib.php</var>, add the <var>$config</var> +array in that file. Then save the file in: <var>config/image_lib.php</var> and it will be used automatically. You +will NOT need to use the <dfn>$this->image_lib->initialize</dfn> function if you save your preferences in a config file.</p> + + +<h2>$this->image_lib->resize()</h2> + +<p>The image resizing function lets you resize the original image, create a copy (with or without resizing), +or create a thumbnail image.</p> + +<p>For practical purposes there is no difference between creating a copy and creating +a thumbnail except a thumb will have the thumbnail marker as part of the name (ie, mypic_thumb.jpg).</p> + +<p>All preferences listed in the table above are available for this function except these three: rotation_angle, x_axis, and y_axis.</p> + +<h3>Creating a Thumbnail</h3> + +<p>The resizing function will create a thumbnail file (and preserve the original) if you set this preference to TRUE:</p> + +<code>$config['create_thumb'] = TRUE;</code> + +<p>This single preference determines whether a thumbnail is created or not.</p> + +<h3>Creating a Copy</h3> + +<p>The resizing function will create a copy of the image file (and preserve the original) if you set +a path and/or a new filename using this preference:</p> + +<code>$config['new_image'] = '/path/to/new_image.jpg';</code> + +<p>Notes regarding this preference:</p> +<ul> +<li>If only the new image name is specified it will be placed in the same folder as the original</li> +<li>If only the path is specified, the new image will be placed in the destination with the same name as the original.</li> +<li>If both the path and image name are specified it will placed in its own destination and given the new name.</li> +</ul> + + +<h3>Resizing the Original Image</h3> + +<p>If neither of the two preferences listed above (create_thumb, and new_image) are used, the resizing function will instead +target the original image for processing.</p> + + +<h2>$this->image_lib->crop()</h2> + +<p>The cropping function works nearly identically to the resizing function except it requires that you set +preferences for the X and Y axis (in pixels) specifying where to crop, like this:</p> + +<code>$config['x_axis'] = '100';<br /> +$config['y_axis'] = '40';</code> + +<p>All preferences listed in the table above are available for this function except these: rotation_angle, width, height, create_thumb, new_image.</p> + +<p>Here's an example showing how you might crop an image:</p> + +<code>$config['image_library'] = 'imagemagick';<br /> +$config['library_path'] = '/usr/X11R6/bin/';<br /> +$config['source_image'] = '/path/to/image/mypic.jpg';<br /> +$config['x_axis'] = '100';<br /> +$config['y_axis'] = '60';<br /> +<br /> +$this->image_lib->initialize($config); +<br /> +<br /> +if ( ! $this->image_lib->crop())<br /> +{<br /> + echo $this->image_lib->display_errors();<br /> +}</code> + + +<p>Note: Without a visual interface it is difficult to crop images, so this function is not very useful +unless you intend to build such an interface. That's exactly what we did using for the photo +gallery module in ExpressionEngine, the CMS we develop. We added a JavaScript UI that lets the cropping +area be selected.</p> + +<h2>$this->image_lib->rotate()</h2> + +<p>The image rotation function requires that the angle of rotation be set via its preference:</p> + +<code>$config['rotation_angle'] = '90';</code> + +<p>There are 5 rotation options:</p> + +<ol> +<li>90 - rotates counter-clockwise by 90 degrees.</li> +<li>180 - rotates counter-clockwise by 180 degrees.</li> +<li>270 - rotates counter-clockwise by 270 degrees.</li> +<li>hor - flips the image horizontally.</li> +<li>vrt - flips the image vertically.</li> +</ol> + +<p>Here's an example showing how you might rotate an image:</p> + +<code>$config['image_library'] = 'netpbm';<br /> +$config['library_path'] = '/usr/bin/';<br /> +$config['source_image'] = '/path/to/image/mypic.jpg';<br /> +$config['rotation_angle'] = 'hor';<br /> +<br /> +$this->image_lib->initialize($config); +<br /> +<br /> +if ( ! $this->image_lib->rotate())<br /> +{<br /> + echo $this->image_lib->display_errors();<br /> +}</code> + + + +<h2>$this->image_lib->clear()</h2> +<p>The clear function resets all of the values used when processing an image. You will want to call this if you are processing images in a loop.</p> +<p><code>$this->image_lib->clear();</code></p> +<p> </p> +<h1>Image Watermarking</h1> + +<p>The Watermarking feature requires the GD/GD2 library.</p> + + +<h2>Two Types of Watermarking</h2> + +<p>There are two types of watermarking that you can use:</p> + +<ul> +<li><strong>Text</strong>: The watermark message will be generating using text, either with a True Type font that you specify, or +using the native text output that the GD library supports. If you use the True Type version your GD installation +must be compiled with True Type support (most are, but not all).</li> + +<li><strong>Overlay</strong>: The watermark message will be generated by overlaying an image (usually a transparent PNG or GIF) +containing your watermark over the source image.</li> + +</ul> + + +<h2>Watermarking an Image</h2> + +<p>Just as with the other functions (resizing, cropping, and rotating) the general process for watermarking +involves setting the preferences corresponding to the action you intend to perform, then +calling the watermark function. Here is an example:</p> + +<code> +$config['source_image'] = '/path/to/image/mypic.jpg';<br /> +$config['wm_text'] = 'Copyright 2006 - John Doe';<br /> +$config['wm_type'] = 'text';<br /> +$config['wm_font_path'] = './system/fonts/texb.ttf';<br /> +$config['wm_font_size'] = '16';<br /> +$config['wm_font_color'] = 'ffffff';<br /> +$config['wm_vrt_alignment'] = 'bottom';<br /> +$config['wm_hor_alignment'] = 'center';<br /> +$config['wm_padding'] = '20';<br /> +<br /> +$this->image_lib->initialize($config); +<br /> +<br /> +$this->image_lib->watermark();</code> + + +<p>The above example will use a 16 pixel True Type font to create the text "Copyright 2006 - John Doe". The watermark +will be positioned at the bottom/center of the image, 20 pixels from the bottom of the image.</p> + +<p class="important"><strong>Note:</strong> In order for the image class to be allowed to do any processing, the image file must have "write" file permissions. For example, 777.</p> + + +<h2>Watermarking Preferences</h2> + +<p>This table shown the preferences that are available for both types of watermarking (text or overlay)</p> + +<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder"> +<tr> +<th>Preference</th> +<th>Default Value</th> +<th>Options</th> +<th>Description</th> +</tr> + +<tr> +<td class="td"><strong>wm_type</strong></td> +<td class="td">text</td> +<td class="td">text, overlay</td> +<td class="td">Sets the type of watermarking that should be used.</td> +</tr> + +<tr> +<td class="td"><strong>source_image</strong></td> +<td class="td">None</td> +<td class="td">None</td> +<td class="td">Sets the source image name/path. The path must be a relative or absolute server path, not a URL.</td> +</tr> + +<tr> +<td class="td"><strong>dynamic_output</strong></td> +<td class="td">FALSE</td> +<td class="td">TRUE/FALSE (boolean)</td> +<td class="td">Determines whether the new image file should be written to disk or generated dynamically. Note: If you choose the dynamic setting, only one image can be shown at a time, and it can't be positioned on the page. It simply outputs the raw image dynamically to your browser, along with image headers.</td> +</tr> + +<tr> +<td class="td"><strong>quality</strong></td> +<td class="td">90%</td> +<td class="td">1 - 100%</td> +<td class="td">Sets the quality of the image. The higher the quality the larger the file size.</td> +</tr> + +<tr> +<td class="td"><strong>padding</strong></td> +<td class="td">None</td> +<td class="td">A number</td> +<td class="td">The amount of padding, set in pixels, that will be applied to the watermark to set it away from the edge of your images.</td> +</tr> + +<tr> +<td class="td"><strong>wm_vrt_alignment</strong></td> +<td class="td">bottom</td> +<td class="td">top, middle, bottom</td> +<td class="td">Sets the vertical alignment for the watermark image.</td> +</tr> + +<tr> +<td class="td"><strong>wm_hor_alignment</strong></td> +<td class="td">center</td> +<td class="td">left, center, right</td> +<td class="td">Sets the horizontal alignment for the watermark image.</td> +</tr> + +<tr> +<td class="td"><strong>wm_hor_offset</strong></td> +<td class="td">None</td> +<td class="td">None</td> +<td class="td">You may specify a horizontal offset (in pixels) to apply to the watermark position. The offset normally moves the watermark to the right, except if you have your alignment set to "right" then your offset value will move the watermark toward the left of the image.</td> +</tr> + +<tr> +<td class="td"><strong>wm_vrt_offset</strong></td> +<td class="td">None</td> +<td class="td">None</td> +<td class="td">You may specify a vertical offset (in pixels) to apply to the watermark position. The offset normally moves the watermark down, except if you have your alignment set to "bottom" then your offset value will move the watermark toward the top of the image.</td> +</tr> + +</table> + + + +<h3>Text Preferences</h3> +<p>This table shown the preferences that are available for the text type of watermarking.</p> + + +<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder"> +<tr> +<th>Preference</th> +<th>Default Value</th> +<th>Options</th> +<th>Description</th> +</tr> + +<tr> +<td class="td"><strong>wm_text</strong></td> +<td class="td">None</td> +<td class="td">None</td> +<td class="td">The text you would like shown as the watermark. Typically this will be a copyright notice.</td> +</tr> + +<tr> +<td class="td"><strong>wm_font_path</strong></td> +<td class="td">None</td> +<td class="td">None</td> +<td class="td">The server path to the True Type Font you would like to use. If you do not use this option, the native GD font will be used.</td> +</tr> + +<tr> +<td class="td"><strong>wm_font_size</strong></td> +<td class="td">16</td> +<td class="td">None</td> +<td class="td">The size of the text. Note: If you are not using the True Type option above, the number is set using a range of 1 - 5. Otherwise, you can use any valid pixel size for the font you're using.</td> +</tr> + +<tr> +<td class="td"><strong>wm_font_color</strong></td> +<td class="td">ffffff</td> +<td class="td">None</td> +<td class="td">The font color, specified in hex. Note, you must use the full 6 character hex value (ie, 993300), rather than the three character abbreviated version (ie fff).</td> +</tr> + + +<tr> +<td class="td"><strong>wm_shadow_color</strong></td> +<td class="td">None</td> +<td class="td">None</td> +<td class="td">The color of the drop shadow, specified in hex. If you leave this blank a drop shadow will not be used. Note, you must use the full 6 character hex value (ie, 993300), rather than the three character abbreviated version (ie fff).</td> +</tr> + +<tr> +<td class="td"><strong>wm_shadow_distance</strong></td> +<td class="td">3</td> +<td class="td">None</td> +<td class="td">The distance (in pixels) from the font that the drop shadow should appear.</td> +</tr> + +</table> + + + + +<h3>Overlay Preferences</h3> +<p>This table shown the preferences that are available for the overlay type of watermarking.</p> + + +<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder"> +<tr> +<th>Preference</th> +<th>Default Value</th> +<th>Options</th> +<th>Description</th> +</tr> + +<tr> +<td class="td"><strong>wm_overlay_path</strong></td> +<td class="td">None</td> +<td class="td">None</td> +<td class="td">The server path to the image you wish to use as your watermark. Required only if you are using the overlay method.</td> +</tr> + +<tr> +<td class="td"><strong>wm_opacity</strong></td> +<td class="td">50</td> +<td class="td">1 - 100</td> +<td class="td">Image opacity. You may specify the opacity (i.e. transparency) of your watermark image. This allows the watermark to be faint and not completely obscure the details from the original image behind it. A 50% opacity is typical.</td> +</tr> + +<tr> +<td class="td"><strong>wm_x_transp</strong></td> +<td class="td">4</td> +<td class="td">A number</td> +<td class="td">If your watermark image is a PNG or GIF image, you may specify a color on the image to be "transparent". This setting (along with the next) will allow you to specify that color. This works by specifying the "X" and "Y" coordinate pixel (measured from the upper left) within the image that corresponds to a pixel representative of the color you want to be transparent.</td> +</tr> + +<tr> +<td class="td"><strong>wm_y_transp</strong></td> +<td class="td">4</td> +<td class="td">A number</td> +<td class="td">Along with the previous setting, this allows you to specify the coordinate to a pixel representative of the color you want to be transparent.</td> +</tr> +</table> + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="table.html">HTML Table Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="input.html">Input Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/input.html b/user_guide/libraries/input.html index ad73dffb7..f210c18f1 100644 --- a/user_guide/libraries/input.html +++ b/user_guide/libraries/input.html @@ -1,231 +1,231 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Input Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Input and Security Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>Input Class</h1>
-
-<p>The Input Class serves two purposes:</p>
-
-<ol>
-<li>It pre-processes global input data for security.</li>
-<li>It provides some helper functions for fetching input data and pre-processing it.</li>
-</ol>
-
-<p class="important"><strong>Note:</strong> This class is initialized automatically by the system so there is no need to do it manually.</p>
-
-
-<h2>Security Filtering</h2>
-
-<p>The security filtering function is called automatically when a new <a href="../general/controllers.html">controller</a> is invoked. It does the following:</p>
-
-<ul>
-<li>Destroys the global GET array. Since CodeIgniter does not utilize GET strings, there is no reason to allow it.</li>
-<li>Destroys all global variables in the event register_globals is turned on.</li>
-<li>Filters the POST/COOKIE array keys, permitting only alpha-numeric (and a few other) characters.</li>
-<li>Provides XSS (Cross-site Scripting Hacks) filtering. This can be enabled globally, or upon request.</li>
-<li>Standardizes newline characters to \n</li>
-</ul>
-
-
-<h2>XSS Filtering</h2>
-
-<p>CodeIgniter comes with a Cross Site Scripting Hack prevention filter which can either run automatically to filter
-all POST and COOKIE data that is encountered, or you can run it on a per item basis. By default it does <strong>not</strong>
-run globally since it requires a bit of processing overhead, and since you may not need it in all cases.</p>
-
-<p>The XSS filter looks for commonly used techniques to trigger Javascript or other types of code that attempt to hijack cookies
-or do other malicious things. If anything disallowed is encountered it is rendered safe by converting the data to character entities.</p>
-
-<p>
-Note: This function should only be used to deal with data upon submission. It's not something that should be used for general runtime processing since it requires a fair amount of processing overhead.</p>
-
-
-<p>To filter data through the XSS filter use this function:</p>
-
-<h2>$this->input->xss_clean()</h2>
-
-<p>Here is an usage example:</p>
-
-<code>$data = $this->input->xss_clean($data);</code>
-
-<p>If you want the filter to run automatically every time it encounters POST or COOKIE data you can enable it by opening your
-<kbd>application/config/config.php</kbd> file and setting this:</p>
-
-<code>$config['global_xss_filtering'] = TRUE;</code>
-
-<p>Note: If you use the form validation class, it gives you the option of XSS filtering as well.</p>
-
-<p>An optional second parameter, <dfn>is_image</dfn>, allows this function to be used to test images for potential XSS attacks, useful for file upload security. When this second parameter is set to <dfn>TRUE</dfn>, instead of returning an altered string, the function returns TRUE if the image is safe, and FALSE if it contained potentially malicious information that a browser may attempt to execute.</p>
-
-<code>if ($this->input->xss_clean($file, TRUE) === FALSE)<br />
-{<br />
- // file failed the XSS test<br />
-}</code>
-
-
-<h2>Using POST, COOKIE, or SERVER Data</h2>
-
-<p>CodeIgniter comes with three helper functions that let you fetch POST, COOKIE or SERVER items. The main advantage of using the provided
-functions rather than fetching an item directly ($_POST['something']) is that the functions will check to see if the item is set and
-return false (boolean) if not. This lets you conveniently use data without having to test whether an item exists first.
-In other words, normally you might do something like this:</p>
-
-<code>
-if ( ! isset($_POST['something']))<br />
-{<br />
- $something = FALSE;<br />
-}<br />
-else<br />
-{<br />
- $something = $_POST['something'];<br />
-}</code>
-
-<p>With CodeIgniter's built in functions you can simply do this:</p>
-
-<code>$something = $this->input->post('something');</code>
-
-<p>The three functions are:</p>
-
-<ul>
-<li>$this->input->post()</li>
-<li>$this->input->cookie()</li>
-<li>$this->input->server()</li>
-</ul>
-
-<h2>$this->input->post()</h2>
-
-<p>The first parameter will contain the name of the POST item you are looking for:</p>
-
-<code>$this->input->post('some_data');</code>
-
-<p>The function returns FALSE (boolean) if the item you are attempting to retrieve does not exist.</p>
-
-<p>The second optional parameter lets you run the data through the XSS filter. It's enabled by setting the second parameter to boolean TRUE;</p>
-
-<code>$this->input->post('some_data', TRUE);</code>
-
-<h2>$this->input->get()</h2>
-
-<p>This function is identical to the post function, only it fetches get data:</p>
-
-<code>$this->input->get('some_data', TRUE);</code>
-
-<h2>$this->input->get_post()</h2>
-
-<p>This function will search through both the post and get streams for data, looking first in post, and then in get:</p>
-
-<code>$this->input->get_post('some_data', TRUE);</code>
-
-<h2>$this->input->cookie()</h2>
-
-<p>This function is identical to the post function, only it fetches cookie data:</p>
-
-<code>$this->input->cookie('some_data', TRUE);</code>
-
-<h2>$this->input->server()</h2>
-
-<p>This function is identical to the above functions, only it fetches server data:</p>
-
-<code>$this->input->server('some_data');</code>
-
-
-
-
-<h2>$this->input->ip_address()</h2>
-<p>Returns the IP address for the current user. If the IP address is not valid, the function will return an IP of: 0.0.0.0</p>
-<code>echo $this->input->ip_address();</code>
-
-
-<h2>$this->input->valid_ip(<var>$ip</var>)</h2>
-
-<p>Takes an IP address as input and returns TRUE or FALSE (boolean) if it is valid or not. Note: The $this->input->ip_address() function above
-validates the IP automatically.</p>
-
-<code>if ( ! $this->input->valid_ip($ip))<br />
-{<br />
- echo 'Not Valid';<br />
-}<br />
-else<br />
-{<br />
- echo 'Valid';<br />
-}</code>
-
-
-<h2>$this->input->user_agent()</h2>
-<p>Returns the user agent (web browser) being used by the current user. Returns FALSE if it's not available.</p>
-<code>echo $this->input->user_agent();</code>
-
-
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="image_lib.html">Image Manipulation Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="loader.html">Loader Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Input Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Input and Security Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>Input Class</h1> + +<p>The Input Class serves two purposes:</p> + +<ol> +<li>It pre-processes global input data for security.</li> +<li>It provides some helper functions for fetching input data and pre-processing it.</li> +</ol> + +<p class="important"><strong>Note:</strong> This class is initialized automatically by the system so there is no need to do it manually.</p> + + +<h2>Security Filtering</h2> + +<p>The security filtering function is called automatically when a new <a href="../general/controllers.html">controller</a> is invoked. It does the following:</p> + +<ul> +<li>Destroys the global GET array. Since CodeIgniter does not utilize GET strings, there is no reason to allow it.</li> +<li>Destroys all global variables in the event register_globals is turned on.</li> +<li>Filters the POST/COOKIE array keys, permitting only alpha-numeric (and a few other) characters.</li> +<li>Provides XSS (Cross-site Scripting Hacks) filtering. This can be enabled globally, or upon request.</li> +<li>Standardizes newline characters to \n</li> +</ul> + + +<h2>XSS Filtering</h2> + +<p>CodeIgniter comes with a Cross Site Scripting Hack prevention filter which can either run automatically to filter +all POST and COOKIE data that is encountered, or you can run it on a per item basis. By default it does <strong>not</strong> +run globally since it requires a bit of processing overhead, and since you may not need it in all cases.</p> + +<p>The XSS filter looks for commonly used techniques to trigger Javascript or other types of code that attempt to hijack cookies +or do other malicious things. If anything disallowed is encountered it is rendered safe by converting the data to character entities.</p> + +<p> +Note: This function should only be used to deal with data upon submission. It's not something that should be used for general runtime processing since it requires a fair amount of processing overhead.</p> + + +<p>To filter data through the XSS filter use this function:</p> + +<h2>$this->input->xss_clean()</h2> + +<p>Here is an usage example:</p> + +<code>$data = $this->input->xss_clean($data);</code> + +<p>If you want the filter to run automatically every time it encounters POST or COOKIE data you can enable it by opening your +<kbd>application/config/config.php</kbd> file and setting this:</p> + +<code>$config['global_xss_filtering'] = TRUE;</code> + +<p>Note: If you use the form validation class, it gives you the option of XSS filtering as well.</p> + +<p>An optional second parameter, <dfn>is_image</dfn>, allows this function to be used to test images for potential XSS attacks, useful for file upload security. When this second parameter is set to <dfn>TRUE</dfn>, instead of returning an altered string, the function returns TRUE if the image is safe, and FALSE if it contained potentially malicious information that a browser may attempt to execute.</p> + +<code>if ($this->input->xss_clean($file, TRUE) === FALSE)<br /> +{<br /> + // file failed the XSS test<br /> +}</code> + + +<h2>Using POST, COOKIE, or SERVER Data</h2> + +<p>CodeIgniter comes with three helper functions that let you fetch POST, COOKIE or SERVER items. The main advantage of using the provided +functions rather than fetching an item directly ($_POST['something']) is that the functions will check to see if the item is set and +return false (boolean) if not. This lets you conveniently use data without having to test whether an item exists first. +In other words, normally you might do something like this:</p> + +<code> +if ( ! isset($_POST['something']))<br /> +{<br /> + $something = FALSE;<br /> +}<br /> +else<br /> +{<br /> + $something = $_POST['something'];<br /> +}</code> + +<p>With CodeIgniter's built in functions you can simply do this:</p> + +<code>$something = $this->input->post('something');</code> + +<p>The three functions are:</p> + +<ul> +<li>$this->input->post()</li> +<li>$this->input->cookie()</li> +<li>$this->input->server()</li> +</ul> + +<h2>$this->input->post()</h2> + +<p>The first parameter will contain the name of the POST item you are looking for:</p> + +<code>$this->input->post('some_data');</code> + +<p>The function returns FALSE (boolean) if the item you are attempting to retrieve does not exist.</p> + +<p>The second optional parameter lets you run the data through the XSS filter. It's enabled by setting the second parameter to boolean TRUE;</p> + +<code>$this->input->post('some_data', TRUE);</code> + +<h2>$this->input->get()</h2> + +<p>This function is identical to the post function, only it fetches get data:</p> + +<code>$this->input->get('some_data', TRUE);</code> + +<h2>$this->input->get_post()</h2> + +<p>This function will search through both the post and get streams for data, looking first in post, and then in get:</p> + +<code>$this->input->get_post('some_data', TRUE);</code> + +<h2>$this->input->cookie()</h2> + +<p>This function is identical to the post function, only it fetches cookie data:</p> + +<code>$this->input->cookie('some_data', TRUE);</code> + +<h2>$this->input->server()</h2> + +<p>This function is identical to the above functions, only it fetches server data:</p> + +<code>$this->input->server('some_data');</code> + + + + +<h2>$this->input->ip_address()</h2> +<p>Returns the IP address for the current user. If the IP address is not valid, the function will return an IP of: 0.0.0.0</p> +<code>echo $this->input->ip_address();</code> + + +<h2>$this->input->valid_ip(<var>$ip</var>)</h2> + +<p>Takes an IP address as input and returns TRUE or FALSE (boolean) if it is valid or not. Note: The $this->input->ip_address() function above +validates the IP automatically.</p> + +<code>if ( ! $this->input->valid_ip($ip))<br /> +{<br /> + echo 'Not Valid';<br /> +}<br /> +else<br /> +{<br /> + echo 'Valid';<br /> +}</code> + + +<h2>$this->input->user_agent()</h2> +<p>Returns the user agent (web browser) being used by the current user. Returns FALSE if it's not available.</p> +<code>echo $this->input->user_agent();</code> + + + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="image_lib.html">Image Manipulation Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="loader.html">Loader Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/language.html b/user_guide/libraries/language.html index 0b5e8a214..4967fe0fd 100644 --- a/user_guide/libraries/language.html +++ b/user_guide/libraries/language.html @@ -1,137 +1,137 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Language Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Language Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>Language Class</h1>
-
-<p>The Language Class provides functions to retrieve language files and lines of text for purposes of internationalization.</p>
-
-<p>In your CodeIgniter system folder you'll find one called <dfn>language</dfn> containing sets of language files. You can create
-your own language files as needed in order to display error and other messages in other languages.</p>
-
-<p>Language files are typically stored in your <dfn>system/language</dfn> directory. Alternately you can create a folder called <kbd>language</kbd> inside
-your <kbd>application</kbd> folder and store them there. CodeIgniter will look first in your <dfn>system/application/language</dfn>
-directory. If the directory does not exist or the specified language is not located there CI will instead look in your global
-<dfn>system/language</dfn> folder.</p>
-
-<p class="important"><strong>Note:</strong> Each language should be stored in its own folder. For example, the English files are located at:
-<dfn>system/language/english</dfn></p>
-
-
-
-<h2>Creating Language Files</h2>
-
-<p>Language files must be named with <kbd>_lang.php</kbd> as the file extension. For example, let's say you want to create a file
-containing error messages. You might name it: <kbd>error_lang.php</kbd></p>
-
-<p>Within the file you will assign each line of text to an array called <var>$lang</var> with this prototype:</p>
-
-<code>$lang['language_key'] = "The actual message to be shown";</code>
-
-<p><strong>Note:</strong> It's a good practice to use a common prefix for all messages in a given file to avoid collisions with
-similarly named items in other files. For example, if you are creating error messages you might prefix them with <var>error_</var></p>
-
-<code>$lang['<var>error</var>_email_missing'] = "You must submit an email address";<br />
-$lang['<var>error</var>_url_missing'] = "You must submit a URL";<br />
-$lang['<var>error</var>_username_missing'] = "You must submit a username";</code>
-
-
-<h2>Loading A Language File</h2>
-
-<p>In order to fetch a line from a particular file you must load the file first. Loading a language file is done with the following code:</p>
-
-<code>$this->lang->load('<samp>filename</samp>', '<dfn>language</dfn>');</code>
-
-<p>Where <samp>filename</samp> is the name of the file you wish to load (without the file extension), and <dfn>language</dfn>
-is the language set containing it (ie, english). If the second parameter is missing, the default language set in your
-<kbd>application/config/config.php</kbd> file will be used.</p>
-
-
-<h2>Fetching a Line of Text</h2>
-
-<p>Once your desired language file is loaded you can access any line of text using this function:</p>
-
-<code>$this->lang->line('<samp>language_key</samp>');</code>
-
-<p>Where <samp>language_key</samp> is the array key corresponding to the line you wish to show.</p>
-
-<p>Note: This function simply returns the line. It does not echo it for you.</p>
-
-<h3>Using language lines as form labels</h3>
-
-<p class="important">This feature has been deprecated from the language library and moved to the <kbd>lang()</kbd> function of the <a href="../helpers/language_helper.html">Language helper</a>.</p>
-
-<h2>Auto-loading Languages</h2>
-<p>If you find that you need a particular language globally throughout your application, you can tell CodeIgniter to <a href="../general/autoloader.html">auto-load</a> it during system initialization. This is done by opening the application/config/autoload.php file and adding the language(s) to the autoload array.</p>
-<p> </p>
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="loader.html">Loader Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="output.html">Output Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Language Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Language Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>Language Class</h1> + +<p>The Language Class provides functions to retrieve language files and lines of text for purposes of internationalization.</p> + +<p>In your CodeIgniter system folder you'll find one called <dfn>language</dfn> containing sets of language files. You can create +your own language files as needed in order to display error and other messages in other languages.</p> + +<p>Language files are typically stored in your <dfn>system/language</dfn> directory. Alternately you can create a folder called <kbd>language</kbd> inside +your <kbd>application</kbd> folder and store them there. CodeIgniter will look first in your <dfn>system/application/language</dfn> +directory. If the directory does not exist or the specified language is not located there CI will instead look in your global +<dfn>system/language</dfn> folder.</p> + +<p class="important"><strong>Note:</strong> Each language should be stored in its own folder. For example, the English files are located at: +<dfn>system/language/english</dfn></p> + + + +<h2>Creating Language Files</h2> + +<p>Language files must be named with <kbd>_lang.php</kbd> as the file extension. For example, let's say you want to create a file +containing error messages. You might name it: <kbd>error_lang.php</kbd></p> + +<p>Within the file you will assign each line of text to an array called <var>$lang</var> with this prototype:</p> + +<code>$lang['language_key'] = "The actual message to be shown";</code> + +<p><strong>Note:</strong> It's a good practice to use a common prefix for all messages in a given file to avoid collisions with +similarly named items in other files. For example, if you are creating error messages you might prefix them with <var>error_</var></p> + +<code>$lang['<var>error</var>_email_missing'] = "You must submit an email address";<br /> +$lang['<var>error</var>_url_missing'] = "You must submit a URL";<br /> +$lang['<var>error</var>_username_missing'] = "You must submit a username";</code> + + +<h2>Loading A Language File</h2> + +<p>In order to fetch a line from a particular file you must load the file first. Loading a language file is done with the following code:</p> + +<code>$this->lang->load('<samp>filename</samp>', '<dfn>language</dfn>');</code> + +<p>Where <samp>filename</samp> is the name of the file you wish to load (without the file extension), and <dfn>language</dfn> +is the language set containing it (ie, english). If the second parameter is missing, the default language set in your +<kbd>application/config/config.php</kbd> file will be used.</p> + + +<h2>Fetching a Line of Text</h2> + +<p>Once your desired language file is loaded you can access any line of text using this function:</p> + +<code>$this->lang->line('<samp>language_key</samp>');</code> + +<p>Where <samp>language_key</samp> is the array key corresponding to the line you wish to show.</p> + +<p>Note: This function simply returns the line. It does not echo it for you.</p> + +<h3>Using language lines as form labels</h3> + +<p class="important">This feature has been deprecated from the language library and moved to the <kbd>lang()</kbd> function of the <a href="../helpers/language_helper.html">Language helper</a>.</p> + +<h2>Auto-loading Languages</h2> +<p>If you find that you need a particular language globally throughout your application, you can tell CodeIgniter to <a href="../general/autoloader.html">auto-load</a> it during system initialization. This is done by opening the application/config/autoload.php file and adding the language(s) to the autoload array.</p> +<p> </p> +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="loader.html">Loader Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="output.html">Output Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/loader.html b/user_guide/libraries/loader.html index 0e13d86bb..2680dfab4 100644 --- a/user_guide/libraries/loader.html +++ b/user_guide/libraries/loader.html @@ -1,214 +1,214 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Loader Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Loader Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>Loader Class</h1>
-
-<p>Loader, as the name suggests, is used to load elements. These elements can be libraries (classes) <a href="../general/views.html">View files</a>,
-<a href="../general/helpers.html">Helpers</a>, <a href="../general/plugins.html">Plugins</a>, or your own files.</p>
-
-<p class="important"><strong>Note:</strong> This class is initialized automatically by the system so there is no need to do it manually.</p>
-
-<p>The following functions are available in this class:</p>
-
-
-<h2>$this->load->library('<var>class_name</var>', <samp>$config</samp>, <kbd>'object name'</kbd>)</h2>
-
-
-<p>This function is used to load core classes. Where <var>class_name</var> is the name of the class you want to load.
-Note: We use the terms "class" and "library" interchangeably.</p>
-
-<p>For example, if you would like to send email with CodeIgniter, the first step is to load the email class within your controller:</p>
-
-<code>$this->load->library('email');</code>
-
-<p>Once loaded, the library will be ready for use, using <kbd>$this->email-></kbd><samp><em>some_function</em>()</samp>.
-
-<p>Library files can be stored in subdirectories within the main "libraries" folder, or within your personal <dfn>application/libraries</dfn> folder.
-To load a file located in a subdirectory, simply include the path, relative to the "libraries" folder.
-For example, if you have file located at:</p>
-
-<code>libraries/flavors/chocolate.php</code>
-
-<p>You will load it using:</p>
-
-<code>$this->load->library('flavors/chocolate');</code>
-
-<p>You may nest the file in as many subdirectories as you want.</p>
-
-<h3>Setting options</h3>
-
-<p>The second (optional) parameter allows you to optionally pass configuration setting. You will typically pass these as an array:</p>
-
-<code>
-$config = array (<br />
- 'mailtype' => 'html',<br />
- 'charset' => 'utf-8,<br />
- 'priority' => '1'<br />
- );<br />
-<br />
-$this->load->library('email', $config);</code>
-
-<p>Config options can usually also be set via a config file. Each library is explained in detail in its own page, so please read the information regarding each one you would like to use.</p>
-
-<h3>Assigning a Library to a different object name</h3>
-
-<p>If the third (optional) parameter is blank, the library will usually be assigned to an object with the same name as the library. For example, if the library is named <dfn>Session</dfn>, it
-will be assigned to a variable named <dfn>$this->session</dfn>.</p>
-
-<p>If you prefer to set your own class names you can pass its value to the third parameter:</p>
-
-<code>$this->load->library('session', '', 'my_session');<br /><br />
-
-// Session class is now accessed using:<br /><br />
-
-$this->my_session
-
-</code>
-
-
-
-<h2>$this->load->view('<var>file_name</var>', <samp>$data</samp>, <kbd>true/false</kbd>)</h2>
-
-<p>This function is used to load your View files. If you haven't read the <a href="../general/views.html">Views</a> section of the
-user guide it is recommended that you do since it shows you how this function is typically used.</p>
-
-<p>The first parameter is required. It is the name of the view file you would like to load. Note: The .php file extension does not need to be specified unless you use something other than <kbd>.php</kbd>.</p>
-
-<p>The second <strong>optional</strong> parameter can take
-an associative array or an object as input, which it runs through the PHP <a href="http://www.php.net/extract">extract</a> function to
-convert to variables that can be used in your view files. Again, read the <a href="../general/views.html">Views</a> page to learn
-how this might be useful.</p>
-
-<p>The third <strong>optional</strong> parameter lets you change the behavior of the function so that it returns data as a string
-rather than sending it to your browser. This can be useful if you want to process the data in some way. If you
-set the parameter to <kbd>true</kbd> (boolean) it will return data. The default behavior is <kbd>false</kbd>, which sends it
-to your browser. Remember to assign it to a variable if you want the data returned:</p>
-
-<code>$string = $this->load->view('<var>myfile</var>', '', <kbd>true</kbd>);</code>
-
-
-<h2>$this->load->model('<var>Model_name</var>');</h2>
-<p><code>$this->load->model('<var>Model_name</var>');</code></p>
-<p>If your model is located in a sub-folder, include the relative path from your models folder. For example, if you have a model located at application/models/blog/queries.php you'll load it using:</p>
-<p><code>$this->load->model('<var>blog/queries</var>');</code></p>
-<p>If you would like your model assigned to a different object name you can specify it via the second parameter of the loading
- function:</p>
-<code> $this->load->model('<var>Model_name</var>', '<kbd>fubar</kbd>');<br />
-<br />
-$this-><kbd>fubar</kbd>->function();</code>
-<h2>$this->load->database('<var>options</var>', <kbd>true/false</kbd>)</h2>
-<p>This function lets you load the database class. The two parameters are <strong>optional</strong>. Please see the
-<a href="./database/index.html">database</a> section for more info.</p>
-
-
-<h2>$this->load->scaffolding('<var>table_name</var>')</h2>
-
-<p>This function lets you enable scaffolding. Please see the
-<a href="../general/scaffolding.html">scaffolding</a> section for more info.</p>
-
-
-
-<h2>$this->load->vars(<samp>$array</samp>)</h2>
-
-<p>This function takes an associative array as input and generates variables using the PHP <a href="http://www.php.net/extract">extract</a> function.
-This function produces the same result as using the second parameter of the <dfn>$this->load->view()</dfn> function above. The reason you might
-want to use this function independently is if you would like to set some global variables in the constructor of your controller
-and have them become available in any view file loaded from any function. You can have multiple calls to this function. The data get cached
-and merged into one array for conversion to variables.
-</p>
-
-
-<h2>$this->load->helper('<var>file_name</var>')</h2>
-<p>This function loads helper files, where <var>file_name</var> is the name of the file, without the <kbd>_helper.php</kbd> extension.</p>
-
-
-<h2>$this->load->plugin('<var>file_name</var>')</h2>
-<p>This function loads plugins files, where <var>file_name</var> is the name of the file, without the <kbd>_plugin.php</kbd> extension.</p>
-
-<h2>$this->load->file('<var>filepath/filename</var>', <kbd>true/false</kbd>)</h2>
-<p>This is a generic file loading function. Supply the filepath and name in the first parameter and it will open and read the file.
-By default the data is sent to your browser, just like a View file, but if you set the second parameter to <kbd>true</kbd> (boolean)
-it will instead return the data as a string.</p>
-
-
-<h2>$this->load->lang('<var>file_name</var>')</h2>
-<p>This function is an alias of the <a href="language.html">language loading function</a>: $this->lang->load()</p>
-
-<h2>$this->load->config('<var>file_name</var>')</h2>
-<p>This function is an alias of the <a href="config.html">config file loading function</a>: $this->config->load()</p>
-
-
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="input.html">Input Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="language.html">Language Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Loader Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Loader Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>Loader Class</h1> + +<p>Loader, as the name suggests, is used to load elements. These elements can be libraries (classes) <a href="../general/views.html">View files</a>, +<a href="../general/helpers.html">Helpers</a>, <a href="../general/plugins.html">Plugins</a>, or your own files.</p> + +<p class="important"><strong>Note:</strong> This class is initialized automatically by the system so there is no need to do it manually.</p> + +<p>The following functions are available in this class:</p> + + +<h2>$this->load->library('<var>class_name</var>', <samp>$config</samp>, <kbd>'object name'</kbd>)</h2> + + +<p>This function is used to load core classes. Where <var>class_name</var> is the name of the class you want to load. +Note: We use the terms "class" and "library" interchangeably.</p> + +<p>For example, if you would like to send email with CodeIgniter, the first step is to load the email class within your controller:</p> + +<code>$this->load->library('email');</code> + +<p>Once loaded, the library will be ready for use, using <kbd>$this->email-></kbd><samp><em>some_function</em>()</samp>. + +<p>Library files can be stored in subdirectories within the main "libraries" folder, or within your personal <dfn>application/libraries</dfn> folder. +To load a file located in a subdirectory, simply include the path, relative to the "libraries" folder. +For example, if you have file located at:</p> + +<code>libraries/flavors/chocolate.php</code> + +<p>You will load it using:</p> + +<code>$this->load->library('flavors/chocolate');</code> + +<p>You may nest the file in as many subdirectories as you want.</p> + +<h3>Setting options</h3> + +<p>The second (optional) parameter allows you to optionally pass configuration setting. You will typically pass these as an array:</p> + +<code> +$config = array (<br /> + 'mailtype' => 'html',<br /> + 'charset' => 'utf-8,<br /> + 'priority' => '1'<br /> + );<br /> +<br /> +$this->load->library('email', $config);</code> + +<p>Config options can usually also be set via a config file. Each library is explained in detail in its own page, so please read the information regarding each one you would like to use.</p> + +<h3>Assigning a Library to a different object name</h3> + +<p>If the third (optional) parameter is blank, the library will usually be assigned to an object with the same name as the library. For example, if the library is named <dfn>Session</dfn>, it +will be assigned to a variable named <dfn>$this->session</dfn>.</p> + +<p>If you prefer to set your own class names you can pass its value to the third parameter:</p> + +<code>$this->load->library('session', '', 'my_session');<br /><br /> + +// Session class is now accessed using:<br /><br /> + +$this->my_session + +</code> + + + +<h2>$this->load->view('<var>file_name</var>', <samp>$data</samp>, <kbd>true/false</kbd>)</h2> + +<p>This function is used to load your View files. If you haven't read the <a href="../general/views.html">Views</a> section of the +user guide it is recommended that you do since it shows you how this function is typically used.</p> + +<p>The first parameter is required. It is the name of the view file you would like to load. Note: The .php file extension does not need to be specified unless you use something other than <kbd>.php</kbd>.</p> + +<p>The second <strong>optional</strong> parameter can take +an associative array or an object as input, which it runs through the PHP <a href="http://www.php.net/extract">extract</a> function to +convert to variables that can be used in your view files. Again, read the <a href="../general/views.html">Views</a> page to learn +how this might be useful.</p> + +<p>The third <strong>optional</strong> parameter lets you change the behavior of the function so that it returns data as a string +rather than sending it to your browser. This can be useful if you want to process the data in some way. If you +set the parameter to <kbd>true</kbd> (boolean) it will return data. The default behavior is <kbd>false</kbd>, which sends it +to your browser. Remember to assign it to a variable if you want the data returned:</p> + +<code>$string = $this->load->view('<var>myfile</var>', '', <kbd>true</kbd>);</code> + + +<h2>$this->load->model('<var>Model_name</var>');</h2> +<p><code>$this->load->model('<var>Model_name</var>');</code></p> +<p>If your model is located in a sub-folder, include the relative path from your models folder. For example, if you have a model located at application/models/blog/queries.php you'll load it using:</p> +<p><code>$this->load->model('<var>blog/queries</var>');</code></p> +<p>If you would like your model assigned to a different object name you can specify it via the second parameter of the loading + function:</p> +<code> $this->load->model('<var>Model_name</var>', '<kbd>fubar</kbd>');<br /> +<br /> +$this-><kbd>fubar</kbd>->function();</code> +<h2>$this->load->database('<var>options</var>', <kbd>true/false</kbd>)</h2> +<p>This function lets you load the database class. The two parameters are <strong>optional</strong>. Please see the +<a href="./database/index.html">database</a> section for more info.</p> + + +<h2>$this->load->scaffolding('<var>table_name</var>')</h2> + +<p>This function lets you enable scaffolding. Please see the +<a href="../general/scaffolding.html">scaffolding</a> section for more info.</p> + + + +<h2>$this->load->vars(<samp>$array</samp>)</h2> + +<p>This function takes an associative array as input and generates variables using the PHP <a href="http://www.php.net/extract">extract</a> function. +This function produces the same result as using the second parameter of the <dfn>$this->load->view()</dfn> function above. The reason you might +want to use this function independently is if you would like to set some global variables in the constructor of your controller +and have them become available in any view file loaded from any function. You can have multiple calls to this function. The data get cached +and merged into one array for conversion to variables. +</p> + + +<h2>$this->load->helper('<var>file_name</var>')</h2> +<p>This function loads helper files, where <var>file_name</var> is the name of the file, without the <kbd>_helper.php</kbd> extension.</p> + + +<h2>$this->load->plugin('<var>file_name</var>')</h2> +<p>This function loads plugins files, where <var>file_name</var> is the name of the file, without the <kbd>_plugin.php</kbd> extension.</p> + +<h2>$this->load->file('<var>filepath/filename</var>', <kbd>true/false</kbd>)</h2> +<p>This is a generic file loading function. Supply the filepath and name in the first parameter and it will open and read the file. +By default the data is sent to your browser, just like a View file, but if you set the second parameter to <kbd>true</kbd> (boolean) +it will instead return the data as a string.</p> + + +<h2>$this->load->lang('<var>file_name</var>')</h2> +<p>This function is an alias of the <a href="language.html">language loading function</a>: $this->lang->load()</p> + +<h2>$this->load->config('<var>file_name</var>')</h2> +<p>This function is an alias of the <a href="config.html">config file loading function</a>: $this->config->load()</p> + + + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="input.html">Input Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="language.html">Language Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/output.html b/user_guide/libraries/output.html index 7af2b358e..004e04201 100644 --- a/user_guide/libraries/output.html +++ b/user_guide/libraries/output.html @@ -1,145 +1,145 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Output Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Output Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>Output Class</h1>
-
-<p>The Output class is a small class with one main function: To send the finalized web page to the requesting browser. It is
-also responsible for <a href="../general/caching.html">caching</a> your web pages, if you use that feature.</p>
-
-<p class="important"><strong>Note:</strong> This class is initialized automatically by the system so there is no need to do it manually.</p>
-
-<p>Under normal circumstances you won't even notice the Output class since it works transparently without your intervention.
-For example, when you use the <a href="../libraries/loader.html">Loader</a> class to load a view file, it's automatically
-passed to the Output class, which will be called automatically by CodeIgniter at the end of system execution.
-It is possible, however, for you to manually intervene with the output if you need to, using either of the two following functions:</p>
-
-<h2>$this->output->set_output();</h2>
-
-<p>Permits you to manually set the final output string. Usage example:</p>
-
-<code>$this->output->set_output($data);</code>
-
-<p><strong>Important:</strong> If you do set your output manually, it must be the last thing done in the function you call it from.
-For example, if you build a page in one of your controller functions, don't set the output until the end.</p>
-
-
-<h2>$this->output->get_output();</h2>
-
-<p>Permits you to manually retrieve any output that has been sent for storage in the output class. Usage example:</p>
-<code>$string = $this->output->get_output();</code>
-
-<p>Note that data will only be retrievable from this function if it has been previously sent to the output class by one of the
-CodeIgniter functions like <var>$this->load->view()</var>.</p>
-
-
-<h2>$this->output->set_header();</h2>
-
-<p>Permits you to manually set server headers, which the output class will send for you when outputting the final rendered display. Example:</p>
-
-<code>
-$this->output->set_header("HTTP/1.0 200 OK");<br />
-$this->output->set_header("HTTP/1.1 200 OK");<br />
-$this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT');<br />
-$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");<br />
-$this->output->set_header("Cache-Control: post-check=0, pre-check=0");<br />
-$this->output->set_header("Pragma: no-cache"); </code>
-
-
-<h2>$this->output->set_status_header();</h2>
-
-<p>Permits you to manually set a server status header. Example:</p>
-
-<code>$this->output->set_status_header('401');<br />
-// Sets the header as: Unauthorized</code>
-
-<p><a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">See here</a> for a full list of headers.</p>
-
-<h2>$this->output->enable_profiler();</h2>
-
-<p>Permits you to enable/disable the <a href="../general/profiling.html">Profiler</a>, which will display benchmark and other data
-at the bottom of your pages for debugging and optimization purposes.</p>
-
-<p>To enable the profiler place the following function anywhere within your <a href="../general/controllers.html">Controller</a> functions:</p>
-<code>$this->output->enable_profiler(TRUE);</code>
-
-<p>When enabled a report will be generated and inserted at the bottom of your pages.</p>
-
-<p>To disable the profiler you will use:</p>
-<code>$this->output->enable_profiler(FALSE);</code>
-
-
-<h2>$this->output->cache();</h2>
-<p>The CodeIgniter output library also controls caching. For more information, please see the <a href="../general/caching.html">caching documentation</a>.</p>
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="language.html">Language Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="pagination.html">Pagination Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Output Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Output Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>Output Class</h1> + +<p>The Output class is a small class with one main function: To send the finalized web page to the requesting browser. It is +also responsible for <a href="../general/caching.html">caching</a> your web pages, if you use that feature.</p> + +<p class="important"><strong>Note:</strong> This class is initialized automatically by the system so there is no need to do it manually.</p> + +<p>Under normal circumstances you won't even notice the Output class since it works transparently without your intervention. +For example, when you use the <a href="../libraries/loader.html">Loader</a> class to load a view file, it's automatically +passed to the Output class, which will be called automatically by CodeIgniter at the end of system execution. +It is possible, however, for you to manually intervene with the output if you need to, using either of the two following functions:</p> + +<h2>$this->output->set_output();</h2> + +<p>Permits you to manually set the final output string. Usage example:</p> + +<code>$this->output->set_output($data);</code> + +<p><strong>Important:</strong> If you do set your output manually, it must be the last thing done in the function you call it from. +For example, if you build a page in one of your controller functions, don't set the output until the end.</p> + + +<h2>$this->output->get_output();</h2> + +<p>Permits you to manually retrieve any output that has been sent for storage in the output class. Usage example:</p> +<code>$string = $this->output->get_output();</code> + +<p>Note that data will only be retrievable from this function if it has been previously sent to the output class by one of the +CodeIgniter functions like <var>$this->load->view()</var>.</p> + + +<h2>$this->output->set_header();</h2> + +<p>Permits you to manually set server headers, which the output class will send for you when outputting the final rendered display. Example:</p> + +<code> +$this->output->set_header("HTTP/1.0 200 OK");<br /> +$this->output->set_header("HTTP/1.1 200 OK");<br /> +$this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT');<br /> +$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");<br /> +$this->output->set_header("Cache-Control: post-check=0, pre-check=0");<br /> +$this->output->set_header("Pragma: no-cache"); </code> + + +<h2>$this->output->set_status_header();</h2> + +<p>Permits you to manually set a server status header. Example:</p> + +<code>$this->output->set_status_header('401');<br /> +// Sets the header as: Unauthorized</code> + +<p><a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">See here</a> for a full list of headers.</p> + +<h2>$this->output->enable_profiler();</h2> + +<p>Permits you to enable/disable the <a href="../general/profiling.html">Profiler</a>, which will display benchmark and other data +at the bottom of your pages for debugging and optimization purposes.</p> + +<p>To enable the profiler place the following function anywhere within your <a href="../general/controllers.html">Controller</a> functions:</p> +<code>$this->output->enable_profiler(TRUE);</code> + +<p>When enabled a report will be generated and inserted at the bottom of your pages.</p> + +<p>To disable the profiler you will use:</p> +<code>$this->output->enable_profiler(FALSE);</code> + + +<h2>$this->output->cache();</h2> +<p>The CodeIgniter output library also controls caching. For more information, please see the <a href="../general/caching.html">caching documentation</a>.</p> + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="language.html">Language Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="pagination.html">Pagination Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/pagination.html b/user_guide/libraries/pagination.html index 452a4d213..79e5a5bd0 100644 --- a/user_guide/libraries/pagination.html +++ b/user_guide/libraries/pagination.html @@ -1,218 +1,218 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Pagination Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Pagination Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>Pagination Class</h1>
-
-<p>CodeIgniter's Pagination class is very easy to use, and it is 100% customizable, either dynamically or via stored preferences.</p>
-
-<p>If you are not familiar with the term "pagination", it refers to links that allows you to navigate from page to page, like this:</p>
-
-<code><a href="#">« First</a> <a href="#"><</a> <a href="#">1</a> <a href="#">2</a> <b>3</b> <a href="#">4</a> <a href="#">5</a> <a href="#">></a> <a href="#">Last »</a></code>
-
-<h2>Example</h2>
-
-<p>Here is a simple example showing how to create pagination in one of your <a href="../general/controllers.html">controller</a> functions:</p>
-
-<code>
-$this->load->library('pagination');<br /><br />
-$config['base_url'] = 'http://example.com/index.php/test/page/';<br />
-$config['total_rows'] = '200';<br />
-$config['per_page'] = '20';
-<br /><br />
-$this->pagination->initialize($config);
-
-<br /><br />
-echo $this->pagination->create_links();</code>
-
-<h3>Notes:</h3>
-
-<p>The <var>$config</var> array contains your configuration variables. It is passed to the <dfn>$this->pagination->initialize</dfn> function as shown above. Although there are some twenty items you can configure, at
-minimum you need the three shown. Here is a description of what those items represent:</p>
-
-<ul>
- <li><strong>base_url</strong> This is the full URL to the controller class/function containing your pagination. In the example
- above, it is pointing to a controller called "Test" and a function called "page". Keep in mind that you can
- <a href="../general/routing.html">re-route your URI</a> if you need a different structure.</li>
- <li><strong>total_rows</strong> This number represents the total rows in the result set you are creating pagination for.
- Typically this number will be the total rows that your database query returned.
- </li>
- <li><strong>per_page</strong> The number of items you intend to show per page. In the above example, you would be showing 20 items per page.</li>
-</ul>
-
-<p>The <var>create_links()</var> function returns an empty string when there is no pagination to show.</p>
-
-
-<h3>Setting preferences in a config file</h3>
-
-<p>If you prefer not to set preferences using the above method, you can instead put them into a config file.
-Simply create a new file called <var>pagination.php</var>, add the <var>$config</var>
-array in that file. Then save the file in: <var>config/pagination.php</var> and it will be used automatically. You
-will NOT need to use the <dfn>$this->pagination->initialize</dfn> function if you save your preferences in a config file.</p>
-
-
-<h2>Customizing the Pagination</h2>
-
-<p>The following is a list of all the preferences you can pass to the initialization function to tailor the display.</p>
-
-
-<h4>$config['uri_segment'] = 3;</h4>
-
-<p>The pagination function automatically determines which segment of your URI contains the page number. If you need
-something different you can specify it.</p>
-
-<h4>$config['num_links'] = 2;</h4>
-
-<p>The number of "digit" links you would like before and after the selected page number. For example, the number 2
- will place two digits on either side, as in the example links at the very top of this page.</p>
-<h4>$config['page_query_string'] = TRUE</h4>
-<p>By default, the pagination library assume you are using <a href="../general/urls.html">URI Segments</a>, and constructs your links something like</p>
-<p><code>http://example.com/index.php/test/page/20</code></p>
-<p>If you have $config['enable_query_strings'] set to TRUE your links will automatically be re-written using Query Strings. This option can also be explictly set. Using $config['page_query_string'] set to TRUE, the pagination link will become.</p>
-<p><code>http://example.com/index.php?c=test&m=page&per_page=20</code></p>
-<p>Note that "per_page" is the default query string passed, however can be configured using $config['query_string_segment'] = 'your_string'</p>
-<h2>Adding Enclosing Markup</h2>
-
-<p>If you would like to surround the entire pagination with some markup you can do it with these two prefs:</p>
-
-<h4>$config['full_tag_open'] = '<p>';</h4>
-<p>The opening tag placed on the left side of the entire result.</p>
-
-<h4>$config['full_tag_close'] = '</p>';</h4>
-<p>The closing tag placed on the right side of the entire result.</p>
-
-
-<h2>Customizing the First Link</h2>
-
-<h4>$config['first_link'] = 'First';</h4>
-<p>The text you would like shown in the "first" link on the left.</p>
-
-<h4>$config['first_tag_open'] = '<div>';</h4>
-<p>The opening tag for the "first" link.</p>
-
-<h4>$config['first_tag_close'] = '</div>';</h4>
-<p>The closing tag for the "first" link.</p>
-
-<h2>Customizing the Last Link</h2>
-
-<h4>$config['last_link'] = 'Last';</h4>
-<p>The text you would like shown in the "last" link on the right.</p>
-
-<h4>$config['last_tag_open'] = '<div>';</h4>
-<p>The opening tag for the "last" link.</p>
-
-<h4>$config['last_tag_close'] = '</div>';</h4>
-<p>The closing tag for the "last" link.</p>
-
-<h2>Customizing the "Next" Link</h2>
-
-<h4>$config['next_link'] = '&gt;';</h4>
-<p>The text you would like shown in the "next" page link.</p>
-
-<h4>$config['next_tag_open'] = '<div>';</h4>
-<p>The opening tag for the "next" link.</p>
-
-<h4>$config['next_tag_close'] = '</div>';</h4>
-<p>The closing tag for the "next" link.</p>
-
-<h2>Customizing the "Previous" Link</h2>
-
-<h4>$config['prev_link'] = '&lt;';</h4>
-<p>The text you would like shown in the "previous" page link.</p>
-
-<h4>$config['prev_tag_open'] = '<div>';</h4>
-<p>The opening tag for the "previous" link.</p>
-
-<h4>$config['prev_tag_close'] = '</div>';</h4>
-<p>The closing tag for the "previous" link.</p>
-
-<h2>Customizing the "Current Page" Link</h2>
-
-<h4>$config['cur_tag_open'] = '<b>';</h4>
-<p>The opening tag for the "current" link.</p>
-
-<h4>$config['cur_tag_close'] = '</b>';</h4>
-<p>The closing tag for the "current" link.</p>
-
-
-<h2>Customizing the "Digit" Link</h2>
-
-<h4>$config['num_tag_open'] = '<div>';</h4>
-<p>The opening tag for the "digit" link.</p>
-
-<h4>$config['num_tag_close'] = '</div>';</h4>
-<p>The closing tag for the "digit" link.</p>
-
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="output.html">Output Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="sessions.html">Session Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Pagination Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Pagination Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>Pagination Class</h1> + +<p>CodeIgniter's Pagination class is very easy to use, and it is 100% customizable, either dynamically or via stored preferences.</p> + +<p>If you are not familiar with the term "pagination", it refers to links that allows you to navigate from page to page, like this:</p> + +<code><a href="#">« First</a> <a href="#"><</a> <a href="#">1</a> <a href="#">2</a> <b>3</b> <a href="#">4</a> <a href="#">5</a> <a href="#">></a> <a href="#">Last »</a></code> + +<h2>Example</h2> + +<p>Here is a simple example showing how to create pagination in one of your <a href="../general/controllers.html">controller</a> functions:</p> + +<code> +$this->load->library('pagination');<br /><br /> +$config['base_url'] = 'http://example.com/index.php/test/page/';<br /> +$config['total_rows'] = '200';<br /> +$config['per_page'] = '20'; +<br /><br /> +$this->pagination->initialize($config); + +<br /><br /> +echo $this->pagination->create_links();</code> + +<h3>Notes:</h3> + +<p>The <var>$config</var> array contains your configuration variables. It is passed to the <dfn>$this->pagination->initialize</dfn> function as shown above. Although there are some twenty items you can configure, at +minimum you need the three shown. Here is a description of what those items represent:</p> + +<ul> + <li><strong>base_url</strong> This is the full URL to the controller class/function containing your pagination. In the example + above, it is pointing to a controller called "Test" and a function called "page". Keep in mind that you can + <a href="../general/routing.html">re-route your URI</a> if you need a different structure.</li> + <li><strong>total_rows</strong> This number represents the total rows in the result set you are creating pagination for. + Typically this number will be the total rows that your database query returned. + </li> + <li><strong>per_page</strong> The number of items you intend to show per page. In the above example, you would be showing 20 items per page.</li> +</ul> + +<p>The <var>create_links()</var> function returns an empty string when there is no pagination to show.</p> + + +<h3>Setting preferences in a config file</h3> + +<p>If you prefer not to set preferences using the above method, you can instead put them into a config file. +Simply create a new file called <var>pagination.php</var>, add the <var>$config</var> +array in that file. Then save the file in: <var>config/pagination.php</var> and it will be used automatically. You +will NOT need to use the <dfn>$this->pagination->initialize</dfn> function if you save your preferences in a config file.</p> + + +<h2>Customizing the Pagination</h2> + +<p>The following is a list of all the preferences you can pass to the initialization function to tailor the display.</p> + + +<h4>$config['uri_segment'] = 3;</h4> + +<p>The pagination function automatically determines which segment of your URI contains the page number. If you need +something different you can specify it.</p> + +<h4>$config['num_links'] = 2;</h4> + +<p>The number of "digit" links you would like before and after the selected page number. For example, the number 2 + will place two digits on either side, as in the example links at the very top of this page.</p> +<h4>$config['page_query_string'] = TRUE</h4> +<p>By default, the pagination library assume you are using <a href="../general/urls.html">URI Segments</a>, and constructs your links something like</p> +<p><code>http://example.com/index.php/test/page/20</code></p> +<p>If you have $config['enable_query_strings'] set to TRUE your links will automatically be re-written using Query Strings. This option can also be explictly set. Using $config['page_query_string'] set to TRUE, the pagination link will become.</p> +<p><code>http://example.com/index.php?c=test&m=page&per_page=20</code></p> +<p>Note that "per_page" is the default query string passed, however can be configured using $config['query_string_segment'] = 'your_string'</p> +<h2>Adding Enclosing Markup</h2> + +<p>If you would like to surround the entire pagination with some markup you can do it with these two prefs:</p> + +<h4>$config['full_tag_open'] = '<p>';</h4> +<p>The opening tag placed on the left side of the entire result.</p> + +<h4>$config['full_tag_close'] = '</p>';</h4> +<p>The closing tag placed on the right side of the entire result.</p> + + +<h2>Customizing the First Link</h2> + +<h4>$config['first_link'] = 'First';</h4> +<p>The text you would like shown in the "first" link on the left.</p> + +<h4>$config['first_tag_open'] = '<div>';</h4> +<p>The opening tag for the "first" link.</p> + +<h4>$config['first_tag_close'] = '</div>';</h4> +<p>The closing tag for the "first" link.</p> + +<h2>Customizing the Last Link</h2> + +<h4>$config['last_link'] = 'Last';</h4> +<p>The text you would like shown in the "last" link on the right.</p> + +<h4>$config['last_tag_open'] = '<div>';</h4> +<p>The opening tag for the "last" link.</p> + +<h4>$config['last_tag_close'] = '</div>';</h4> +<p>The closing tag for the "last" link.</p> + +<h2>Customizing the "Next" Link</h2> + +<h4>$config['next_link'] = '&gt;';</h4> +<p>The text you would like shown in the "next" page link.</p> + +<h4>$config['next_tag_open'] = '<div>';</h4> +<p>The opening tag for the "next" link.</p> + +<h4>$config['next_tag_close'] = '</div>';</h4> +<p>The closing tag for the "next" link.</p> + +<h2>Customizing the "Previous" Link</h2> + +<h4>$config['prev_link'] = '&lt;';</h4> +<p>The text you would like shown in the "previous" page link.</p> + +<h4>$config['prev_tag_open'] = '<div>';</h4> +<p>The opening tag for the "previous" link.</p> + +<h4>$config['prev_tag_close'] = '</div>';</h4> +<p>The closing tag for the "previous" link.</p> + +<h2>Customizing the "Current Page" Link</h2> + +<h4>$config['cur_tag_open'] = '<b>';</h4> +<p>The opening tag for the "current" link.</p> + +<h4>$config['cur_tag_close'] = '</b>';</h4> +<p>The closing tag for the "current" link.</p> + + +<h2>Customizing the "Digit" Link</h2> + +<h4>$config['num_tag_open'] = '<div>';</h4> +<p>The opening tag for the "digit" link.</p> + +<h4>$config['num_tag_close'] = '</div>';</h4> +<p>The closing tag for the "digit" link.</p> + + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="output.html">Output Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="sessions.html">Session Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/parser.html b/user_guide/libraries/parser.html index 7d6b2afa5..8151eb127 100644 --- a/user_guide/libraries/parser.html +++ b/user_guide/libraries/parser.html @@ -1,208 +1,208 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Template Parser Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Template Parser Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-
-
-<h1>Template Parser Class</h1>
-
-<p>The Template Parser Class enables you to parse pseudo-variables contained within your view files. It can parse simple
-variables or variable tag pairs. If you've never used a template engine, pseudo-variables look like this:</p>
-
-<code><html><br />
-<head><br />
-<title><kbd>{blog_title}</kbd></title><br />
-</head><br />
-<body><br />
-<br />
-<h3><kbd>{blog_heading}</kbd></h3><br />
-<br />
-<kbd>{blog_entries}</kbd><br />
-<h5><kbd>{title}</kbd></h5><br />
-<p><kbd>{body}</kbd></p><br />
-<kbd>{/blog_entries}</kbd><br />
-
-</body><br />
-</html></code>
-
-<p>These variables are not actual PHP variables, but rather plain text representations that allow you to eliminate
-PHP from your templates (view files).</p>
-
-<p class="important"><strong>Note:</strong> CodeIgniter does <strong>not</strong> require you to use this class
-since using pure PHP in your view pages lets them run a little faster. However, some developers prefer to use a template engine if
-they work with designers who they feel would find some confusion working with PHP.</p>
-
-<p><strong>Also Note:</strong> The Template Parser Class is <strong>not</strong> a
-full-blown template parsing solution. We've kept it very lean on purpose in order to maintain maximum performance.</p>
-
-
-<h2>Initializing the Class</h2>
-
-<p>Like most other classes in CodeIgniter, the Parser class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
-
-<code>$this->load->library('parser');</code>
-<p>Once loaded, the Parser library object will be available using: <dfn>$this->parser</dfn></p>
-
-
-<p>The following functions are available in this library:</p>
-
-<h2>$this->parser->parse()</h2>
-
-<p>This method accepts a template name and data array as input, and it generates a parsed version. Example:</p>
-
-<code>$this->load->library('parser');<br />
-<br />
-$data = array(<br />
- 'blog_title' => 'My Blog Title',<br />
- 'blog_heading' => 'My Blog Heading'<br />
- );<br />
-<br />
-$this->parser->parse('blog_template', $data);</code>
-
-<p>The first parameter contains the name of the <a href="../general/views.html">view file</a> (in this example the file would be called blog_template.php),
-and the second parameter contains an associative array of data to be replaced in the template. In the above example, the
-template would contain two variables: {blog_title} and {blog_heading}</p>
-
-<p>There is no need to "echo" or do something with the data returned by <dfn>$this->parser->parse()</dfn>. It is automatically
-passed to the output class to be sent to the browser. However, if you do want the data returned instead of sent to the output class you can
-pass TRUE (boolean) to the third parameter:</p>
-
-<code>$string = $this->parser->parse('blog_template', $data, TRUE);</code>
-
-
-<h2>Variable Pairs</h2>
-
-<p>The above example code allows simple variables to be replaced. What if you would like an entire block of variables to be
-repeated, with each iteration containing new values? Consider the template example we showed at the top of the page:</p>
-
-<code><html><br />
-<head><br />
-<title><kbd>{blog_title}</kbd></title><br />
-</head><br />
-<body><br />
-<br />
-<h3><kbd>{blog_heading}</kbd></h3><br />
-<br />
-<kbd>{blog_entries}</kbd><br />
-<h5><kbd>{title}</kbd></h5><br />
-<p><kbd>{body}</kbd></p><br />
-<kbd>{/blog_entries}</kbd><br />
-
-</body><br />
-</html></code>
-
-<p>In the above code you'll notice a pair of variables: <kbd>{blog_entries}</kbd> data... <kbd>{/blog_entries}</kbd>.
-In a case like this, the entire chunk of data between these pairs would be repeated multiple times, corresponding
-to the number of rows in a result.</p>
-
-<p>Parsing variable pairs is done using the identical code shown above to parse single variables,
-except, you will add a multi-dimensional array corresponding to your variable pair data.
-Consider this example:</p>
-
-
-<code>$this->load->library('parser');<br />
-<br />
-$data = array(<br />
- 'blog_title' => 'My Blog Title',<br />
- 'blog_heading' => 'My Blog Heading',<br />
- 'blog_entries' => array(<br />
- array('title' => 'Title 1', 'body' => 'Body 1'),<br />
- array('title' => 'Title 2', 'body' => 'Body 2'),<br />
- array('title' => 'Title 3', 'body' => 'Body 3'),<br />
- array('title' => 'Title 4', 'body' => 'Body 4'),<br />
- array('title' => 'Title 5', 'body' => 'Body 5')<br />
- )<br />
- );<br />
-<br />
-$this->parser->parse('blog_template', $data);</code>
-
-<p>If your "pair" data is coming from a database result, which is already a multi-dimensional array, you can simply
-use the database result_array() function:</p>
-
-<code>
-$query = $this->db->query("SELECT * FROM blog");<br />
-<br />
-$this->load->library('parser');<br />
-<br />
-$data = array(<br />
- 'blog_title' => 'My Blog Title',<br />
- 'blog_heading' => 'My Blog Heading',<br />
- 'blog_entries' => $query->result_array()<br />
- );<br />
-<br />
-$this->parser->parse('blog_template', $data);</code>
-
-
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="trackback.html">Trackback Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="typography.html">Typography</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Template Parser Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Template Parser Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + + + +<h1>Template Parser Class</h1> + +<p>The Template Parser Class enables you to parse pseudo-variables contained within your view files. It can parse simple +variables or variable tag pairs. If you've never used a template engine, pseudo-variables look like this:</p> + +<code><html><br /> +<head><br /> +<title><kbd>{blog_title}</kbd></title><br /> +</head><br /> +<body><br /> +<br /> +<h3><kbd>{blog_heading}</kbd></h3><br /> +<br /> +<kbd>{blog_entries}</kbd><br /> +<h5><kbd>{title}</kbd></h5><br /> +<p><kbd>{body}</kbd></p><br /> +<kbd>{/blog_entries}</kbd><br /> + +</body><br /> +</html></code> + +<p>These variables are not actual PHP variables, but rather plain text representations that allow you to eliminate +PHP from your templates (view files).</p> + +<p class="important"><strong>Note:</strong> CodeIgniter does <strong>not</strong> require you to use this class +since using pure PHP in your view pages lets them run a little faster. However, some developers prefer to use a template engine if +they work with designers who they feel would find some confusion working with PHP.</p> + +<p><strong>Also Note:</strong> The Template Parser Class is <strong>not</strong> a +full-blown template parsing solution. We've kept it very lean on purpose in order to maintain maximum performance.</p> + + +<h2>Initializing the Class</h2> + +<p>Like most other classes in CodeIgniter, the Parser class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p> + +<code>$this->load->library('parser');</code> +<p>Once loaded, the Parser library object will be available using: <dfn>$this->parser</dfn></p> + + +<p>The following functions are available in this library:</p> + +<h2>$this->parser->parse()</h2> + +<p>This method accepts a template name and data array as input, and it generates a parsed version. Example:</p> + +<code>$this->load->library('parser');<br /> +<br /> +$data = array(<br /> + 'blog_title' => 'My Blog Title',<br /> + 'blog_heading' => 'My Blog Heading'<br /> + );<br /> +<br /> +$this->parser->parse('blog_template', $data);</code> + +<p>The first parameter contains the name of the <a href="../general/views.html">view file</a> (in this example the file would be called blog_template.php), +and the second parameter contains an associative array of data to be replaced in the template. In the above example, the +template would contain two variables: {blog_title} and {blog_heading}</p> + +<p>There is no need to "echo" or do something with the data returned by <dfn>$this->parser->parse()</dfn>. It is automatically +passed to the output class to be sent to the browser. However, if you do want the data returned instead of sent to the output class you can +pass TRUE (boolean) to the third parameter:</p> + +<code>$string = $this->parser->parse('blog_template', $data, TRUE);</code> + + +<h2>Variable Pairs</h2> + +<p>The above example code allows simple variables to be replaced. What if you would like an entire block of variables to be +repeated, with each iteration containing new values? Consider the template example we showed at the top of the page:</p> + +<code><html><br /> +<head><br /> +<title><kbd>{blog_title}</kbd></title><br /> +</head><br /> +<body><br /> +<br /> +<h3><kbd>{blog_heading}</kbd></h3><br /> +<br /> +<kbd>{blog_entries}</kbd><br /> +<h5><kbd>{title}</kbd></h5><br /> +<p><kbd>{body}</kbd></p><br /> +<kbd>{/blog_entries}</kbd><br /> + +</body><br /> +</html></code> + +<p>In the above code you'll notice a pair of variables: <kbd>{blog_entries}</kbd> data... <kbd>{/blog_entries}</kbd>. +In a case like this, the entire chunk of data between these pairs would be repeated multiple times, corresponding +to the number of rows in a result.</p> + +<p>Parsing variable pairs is done using the identical code shown above to parse single variables, +except, you will add a multi-dimensional array corresponding to your variable pair data. +Consider this example:</p> + + +<code>$this->load->library('parser');<br /> +<br /> +$data = array(<br /> + 'blog_title' => 'My Blog Title',<br /> + 'blog_heading' => 'My Blog Heading',<br /> + 'blog_entries' => array(<br /> + array('title' => 'Title 1', 'body' => 'Body 1'),<br /> + array('title' => 'Title 2', 'body' => 'Body 2'),<br /> + array('title' => 'Title 3', 'body' => 'Body 3'),<br /> + array('title' => 'Title 4', 'body' => 'Body 4'),<br /> + array('title' => 'Title 5', 'body' => 'Body 5')<br /> + )<br /> + );<br /> +<br /> +$this->parser->parse('blog_template', $data);</code> + +<p>If your "pair" data is coming from a database result, which is already a multi-dimensional array, you can simply +use the database result_array() function:</p> + +<code> +$query = $this->db->query("SELECT * FROM blog");<br /> +<br /> +$this->load->library('parser');<br /> +<br /> +$data = array(<br /> + 'blog_title' => 'My Blog Title',<br /> + 'blog_heading' => 'My Blog Heading',<br /> + 'blog_entries' => $query->result_array()<br /> + );<br /> +<br /> +$this->parser->parse('blog_template', $data);</code> + + + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="trackback.html">Trackback Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="typography.html">Typography</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/sessions.html b/user_guide/libraries/sessions.html index 8ceadf240..fbbaa64ef 100644 --- a/user_guide/libraries/sessions.html +++ b/user_guide/libraries/sessions.html @@ -1,311 +1,311 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Session Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Session Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>Session Class</h1>
-
-<p>The Session class permits you maintain a user's "state" and track their activity while they browse your site.
-The Session class stores session information for each user as serialized (and optionally encrypted) data in a cookie.
-It can also store the session data in a database table for added security, as this permits the session ID in the
-user's cookie to be matched against the stored session ID. By default only the cookie is saved. If you choose to
-use the database option you'll need to create the session table as indicated below.
-</p>
-
-<p class="important"><strong>Note:</strong> The Session class does <strong>not</strong> utilize native PHP sessions. It
-generates its own session data, offering more flexibility for developers.</p>
-
-<h2>Initializing a Session</h2>
-
-<p>Sessions will typically run globally with each page load, so the session class must either be
-<a href="../general/libraries.html">initialized</a> in your
-<a href="../general/controllers.html">controller</a> constructors, or it can be
-<a href="../general/autoloader.html">auto-loaded</a> by the system.
-For the most part the session class will run unattended in the background, so simply initializing the class
-will cause it to read, create, and update sessions.</p>
-
-
-<p>To initialize the Session class manually in your controller constructor, use the <dfn>$this->load->library</dfn> function:</p>
-
-<code>$this->load->library('session');</code>
-<p>Once loaded, the Sessions library object will be available using: <dfn>$this->session</dfn></p>
-
-
-<h2>How do Sessions work?</h2>
-
-<p>When a page is loaded, the session class will check to see if valid session data exists in the user's session cookie.
-If sessions data does <strong>not</strong> exist (or if it has expired) a new session will be created and saved in the cookie.
-If a session does exist, its information will be updated and the cookie will be updated. With each update, the session_id will be regenerated.</p>
-
-<p>It's important for you to understand that once initialized, the Session class runs automatically. There is nothing
-you need to do to cause the above behavior to happen. You can, as you'll see below, work with session data or
-even add your own data to a user's session, but the process of reading, writing, and updating a session is automatic.</p>
-
-
-<h2>What is Session Data?</h2>
-
-<p>A <em>session</em>, as far as CodeIgniter is concerned, is simply an array containing the following information:</p>
-
-<ul>
-<li>The user's unique Session ID (this is a statistically random string with very strong entropy, hashed with MD5 for portability, and regenerated (by default) every five minutes)</li>
-<li>The user's IP Address</li>
-<li>The user's User Agent data (the first 50 characters of the browser data string)</li>
-<li>The "last activity" time stamp.</li>
-</ul>
-
-<p>The above data is stored in a cookie as a serialized array with this prototype:</p>
-
-<code>[array]<br />
-(<br />
- 'session_id' => random hash,<br />
- 'ip_address' => 'string - user IP address',<br />
- 'user_agent' => 'string - user agent data',<br />
- 'last_activity' => timestamp<br />
-)</code>
-
-<p>If you have the encryption option enabled, the serialized array will be encrypted before being stored in the cookie,
-making the data highly secure and impervious to being read or altered by someone. More info regarding encryption
-can be <a href="encryption.html">found here</a>, although the Session class will take care of initializing
-and encrypting the data automatically.</p>
-
-<p>Note: Session cookies are only updated every five minutes by default to reduce processor load. If you repeatedly reload a page
-you'll notice that the "last activity" time only updates if five minutes or more has passed since the last time
-the cookie was written. This time is configurable by changing the $config['time_to_update'] line in your system/config/config.php file.</p>
-
-<h2>Retrieving Session Data</h2>
-
-<p>Any piece of information from the session array is available using the following function:</p>
-
-<code>$this->session->userdata('<samp>item</samp>');</code>
-
-<p>Where <samp>item</samp> is the array index corresponding to the item you wish to fetch. For example, to fetch the session ID you
-will do this:</p>
-
-<code>$session_id = $this->session->userdata('<samp>session_id</samp>');</code>
-
-<p><strong>Note:</strong> The function returns FALSE (boolean) if the item you are trying to access does not exist.</p>
-
-
-<h2>Adding Custom Session Data</h2>
-
-<p>A useful aspect of the session array is that you can add your own data to it and it will be stored in the user's cookie.
-Why would you want to do this? Here's one example:</p>
-
-<p>Let's say a particular user logs into your site. Once authenticated,
-you could add their username and email address to the session cookie, making that data globally available to you without
-having to run a database query when you need it.</p>
-
-<p>To add your data to the session array involves passing an array containing your new data to this function:</p>
-
-<code>$this->session->set_userdata(<samp>$array</samp>);</code>
-
-<p>Where <samp>$array</samp> is an associative array containing your new data. Here's an example:</p>
-
-
-<p><code>$newdata = array(<br />
- 'username' => 'johndoe',<br />
- 'email' => 'johndoe@some-site.com',<br />
- 'logged_in' => TRUE<br />
- );<br />
- <br />
- $this->session->set_userdata(<samp>$newdata</samp>);</code></p>
-<p>If you want to add userdata one value at a time, set_userdata() also supports this syntax. </p>
-<p><code>$this->session->set_userdata('some_name', 'some_value');</code></p>
-<p class="important"><strong>Note:</strong> Cookies can only hold 4KB of data, so be careful not to exceed the capacity. The
-encryption process in particular produces a longer data string than the original so keep careful track of how much data you are storing.</p>
-
-<h2>Removing Session Data</h2>
-<p>Just as set_userdata() can be used to add information into a session, unset_userdata() can be used to remove it, by passing the session key. For example, if you wanted to remove 'some_name' from your session information: </p>
-<p><code>$this->session->unset_userdata('some_name');</code></p>
-<p>This function can also be passed an associative array of items to unset.</p>
-<p><code>$array_items = array('username' => '', 'email' => '');<br />
-<br />
-$this->session->unset_userdata(<samp>$array_items</samp>);</code></p>
-<h2>Flashdata</h2>
-<p>CodeIgniter supports "flashdata", or session data that will only be available for the next server request, and are then automatically cleared. These can be very useful, and are typically used for informational or status messages (for example: "record 2 deleted").</p>
-<p>Note: Flash variables are prefaced with "flash_" so avoid this prefix in your own session names.</p>
-<p>To add flashdata:</p>
-<p><code>$this->session->set_flashdata('item', 'value');</code></p>
-<p>You can also pass an array to set_flashdata(), in the same manner as set_userdata(). </p>
-<p>To read a flashdata variable:</p>
-<p><code>$this->session->flashdata('item');</code></p>
-<p>If you find that you need to preserve a flashdata variable through an additional request, you can do so using the keep_flashdata() function.</p>
-<p><code>$this->session->keep_flashdata('item');</code></p>
-<h2>Saving Session Data to a Database</h2>
-<p>While the session data array stored in the user's cookie contains a Session ID,
-unless you store session data in a database there is no way to validate it. For some applications that require little or no
-security, session ID validation may not be needed, but if your application requires security, validation is mandatory.</p>
-
-<p>When session data is available in a database, every time a valid session is found in the user's cookie, a database
-query is performed to match it. If the session ID does not match, the session is destroyed. Session IDs can never
-be updated, they can only be generated when a new session is created.</p>
-
-<p>In order to store sessions, you must first create a database table for this purpose. Here is the basic
-prototype (for MySQL) required by the session class:</p>
-
-<textarea class="textarea" style="width:100%" cols="50" rows="8">
-CREATE TABLE IF NOT EXISTS `ci_sessions` (
-session_id varchar(40) DEFAULT '0' NOT NULL,
-ip_address varchar(16) DEFAULT '0' NOT NULL,
-user_agent varchar(50) NOT NULL,
-last_activity int(10) unsigned DEFAULT 0 NOT NULL,
-user_data text NOT NULL,
-PRIMARY KEY (session_id)
-);</textarea>
-
-<p><strong>Note:</strong> By default the table is called <dfn>ci_sessions</dfn>, but you can name it anything you want
-as long as you update the <kbd>application/config/config.php</kbd> file so that it contains the name you have chosen.
-Once you have created your database table you can enable the database option in your config.php file as follows:</p>
-
-<code>$config['sess_use_database'] = TRUE;</code>
-
-<p>Once enabled, the Session class will store session data in the DB.</p>
-
-<p>Make sure you've specified the table name in your config file as well:</p>
-
-<code>$config['sess_table_name'] = 'ci_sessions";</code>
-
-<p class="important"><strong>Note:</strong> The Session class has built-in garbage collection which clears out expired sessions so you
-do not need to write your own routine to do it.</p>
-
-
-<h2>Destroying a Session </h2>
-<p>To clear the current session: </p>
-<code>$this->session->sess_destroy();</code>
-<p class="important"><strong>Note:</strong> This function should be the last one called, and even flash variables will no longer be available. If you only want some items destroyed and not all, use <dfn>unset_userdata()</dfn>.</p>
-
-
-
-<h2>Session Preferences</h2>
-<p>You'll find the following Session related preferences in your <kbd>application/config/config.php</kbd> file:</p>
-
-
-<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
-<tr>
- <th>Preference</th>
- <th>Default</th>
- <th>Options</th>
- <th>Description</th>
-</tr>
-<tr>
- <td class="td"><strong>sess_cookie_name</strong></td>
- <td class="td">ci_session</td>
- <td class="td">None</td>
- <td class="td">The name you want the session cookie saved as.</td>
-</tr>
-<tr>
- <td class="td"><strong>sess_expiration</strong></td>
- <td class="td">7200</td>
- <td class="td">None</td>
- <td class="td">The number of seconds you would like the session to last. The default value is 2 hours (7200 seconds). If you would like a non-expiring session set the value to zero: 0</td>
-</tr>
-<tr>
- <td class="td"><strong>sess_encrypt_cookie</strong></td>
- <td class="td">FALSE</td>
- <td class="td">TRUE/FALSE (boolean)</td>
- <td class="td">Whether to encrypt the session data.</td>
-</tr>
-<tr>
- <td class="td"><strong>sess_use_database</strong></td>
- <td class="td">FALSE</td>
- <td class="td">TRUE/FALSE (boolean)</td>
- <td class="td">Whether to save the session data to a database. You must create the table before enabling this option.</td>
-</tr>
-<tr>
- <td class="td"><strong>sess_table_name</strong></td>
- <td class="td">ci_sessions</td>
- <td class="td">Any valid SQL table name</td>
- <td class="td">The name of the session database table.</td>
-</tr>
-<tr>
- <td class="td"><strong>sess_time_to_update</strong></td>
- <td class="td">300</td>
- <td class="td">Time in seconds</td>
- <td class="td">This options controls how often the session class will regenerate itself and create a new session id.</td>
-</tr>
-<tr>
- <td class="td"><strong>sess_match_ip</strong></td>
- <td class="td">FALSE</td>
- <td class="td">TRUE/FALSE (boolean)</td>
- <td class="td">Whether to match the user's IP address when reading the session data. Note that some ISPs dynamically
- changes the IP, so if you want a non-expiring session you will likely set this to FALSE.</td>
-</tr>
-<tr>
- <td class="td"><strong>sess_match_useragent</strong></td>
- <td class="td">TRUE</td>
- <td class="td">TRUE/FALSE (boolean)</td>
- <td class="td">Whether to match the User Agent when reading the session data.</td>
-</tr>
-</table>
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="pagination.html">Pagination Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="trackback.html">Trackback Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Session Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Session Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>Session Class</h1> + +<p>The Session class permits you maintain a user's "state" and track their activity while they browse your site. +The Session class stores session information for each user as serialized (and optionally encrypted) data in a cookie. +It can also store the session data in a database table for added security, as this permits the session ID in the +user's cookie to be matched against the stored session ID. By default only the cookie is saved. If you choose to +use the database option you'll need to create the session table as indicated below. +</p> + +<p class="important"><strong>Note:</strong> The Session class does <strong>not</strong> utilize native PHP sessions. It +generates its own session data, offering more flexibility for developers.</p> + +<h2>Initializing a Session</h2> + +<p>Sessions will typically run globally with each page load, so the session class must either be +<a href="../general/libraries.html">initialized</a> in your +<a href="../general/controllers.html">controller</a> constructors, or it can be +<a href="../general/autoloader.html">auto-loaded</a> by the system. +For the most part the session class will run unattended in the background, so simply initializing the class +will cause it to read, create, and update sessions.</p> + + +<p>To initialize the Session class manually in your controller constructor, use the <dfn>$this->load->library</dfn> function:</p> + +<code>$this->load->library('session');</code> +<p>Once loaded, the Sessions library object will be available using: <dfn>$this->session</dfn></p> + + +<h2>How do Sessions work?</h2> + +<p>When a page is loaded, the session class will check to see if valid session data exists in the user's session cookie. +If sessions data does <strong>not</strong> exist (or if it has expired) a new session will be created and saved in the cookie. +If a session does exist, its information will be updated and the cookie will be updated. With each update, the session_id will be regenerated.</p> + +<p>It's important for you to understand that once initialized, the Session class runs automatically. There is nothing +you need to do to cause the above behavior to happen. You can, as you'll see below, work with session data or +even add your own data to a user's session, but the process of reading, writing, and updating a session is automatic.</p> + + +<h2>What is Session Data?</h2> + +<p>A <em>session</em>, as far as CodeIgniter is concerned, is simply an array containing the following information:</p> + +<ul> +<li>The user's unique Session ID (this is a statistically random string with very strong entropy, hashed with MD5 for portability, and regenerated (by default) every five minutes)</li> +<li>The user's IP Address</li> +<li>The user's User Agent data (the first 50 characters of the browser data string)</li> +<li>The "last activity" time stamp.</li> +</ul> + +<p>The above data is stored in a cookie as a serialized array with this prototype:</p> + +<code>[array]<br /> +(<br /> + 'session_id' => random hash,<br /> + 'ip_address' => 'string - user IP address',<br /> + 'user_agent' => 'string - user agent data',<br /> + 'last_activity' => timestamp<br /> +)</code> + +<p>If you have the encryption option enabled, the serialized array will be encrypted before being stored in the cookie, +making the data highly secure and impervious to being read or altered by someone. More info regarding encryption +can be <a href="encryption.html">found here</a>, although the Session class will take care of initializing +and encrypting the data automatically.</p> + +<p>Note: Session cookies are only updated every five minutes by default to reduce processor load. If you repeatedly reload a page +you'll notice that the "last activity" time only updates if five minutes or more has passed since the last time +the cookie was written. This time is configurable by changing the $config['time_to_update'] line in your system/config/config.php file.</p> + +<h2>Retrieving Session Data</h2> + +<p>Any piece of information from the session array is available using the following function:</p> + +<code>$this->session->userdata('<samp>item</samp>');</code> + +<p>Where <samp>item</samp> is the array index corresponding to the item you wish to fetch. For example, to fetch the session ID you +will do this:</p> + +<code>$session_id = $this->session->userdata('<samp>session_id</samp>');</code> + +<p><strong>Note:</strong> The function returns FALSE (boolean) if the item you are trying to access does not exist.</p> + + +<h2>Adding Custom Session Data</h2> + +<p>A useful aspect of the session array is that you can add your own data to it and it will be stored in the user's cookie. +Why would you want to do this? Here's one example:</p> + +<p>Let's say a particular user logs into your site. Once authenticated, +you could add their username and email address to the session cookie, making that data globally available to you without +having to run a database query when you need it.</p> + +<p>To add your data to the session array involves passing an array containing your new data to this function:</p> + +<code>$this->session->set_userdata(<samp>$array</samp>);</code> + +<p>Where <samp>$array</samp> is an associative array containing your new data. Here's an example:</p> + + +<p><code>$newdata = array(<br /> + 'username' => 'johndoe',<br /> + 'email' => 'johndoe@some-site.com',<br /> + 'logged_in' => TRUE<br /> + );<br /> + <br /> + $this->session->set_userdata(<samp>$newdata</samp>);</code></p> +<p>If you want to add userdata one value at a time, set_userdata() also supports this syntax. </p> +<p><code>$this->session->set_userdata('some_name', 'some_value');</code></p> +<p class="important"><strong>Note:</strong> Cookies can only hold 4KB of data, so be careful not to exceed the capacity. The +encryption process in particular produces a longer data string than the original so keep careful track of how much data you are storing.</p> + +<h2>Removing Session Data</h2> +<p>Just as set_userdata() can be used to add information into a session, unset_userdata() can be used to remove it, by passing the session key. For example, if you wanted to remove 'some_name' from your session information: </p> +<p><code>$this->session->unset_userdata('some_name');</code></p> +<p>This function can also be passed an associative array of items to unset.</p> +<p><code>$array_items = array('username' => '', 'email' => '');<br /> +<br /> +$this->session->unset_userdata(<samp>$array_items</samp>);</code></p> +<h2>Flashdata</h2> +<p>CodeIgniter supports "flashdata", or session data that will only be available for the next server request, and are then automatically cleared. These can be very useful, and are typically used for informational or status messages (for example: "record 2 deleted").</p> +<p>Note: Flash variables are prefaced with "flash_" so avoid this prefix in your own session names.</p> +<p>To add flashdata:</p> +<p><code>$this->session->set_flashdata('item', 'value');</code></p> +<p>You can also pass an array to set_flashdata(), in the same manner as set_userdata(). </p> +<p>To read a flashdata variable:</p> +<p><code>$this->session->flashdata('item');</code></p> +<p>If you find that you need to preserve a flashdata variable through an additional request, you can do so using the keep_flashdata() function.</p> +<p><code>$this->session->keep_flashdata('item');</code></p> +<h2>Saving Session Data to a Database</h2> +<p>While the session data array stored in the user's cookie contains a Session ID, +unless you store session data in a database there is no way to validate it. For some applications that require little or no +security, session ID validation may not be needed, but if your application requires security, validation is mandatory.</p> + +<p>When session data is available in a database, every time a valid session is found in the user's cookie, a database +query is performed to match it. If the session ID does not match, the session is destroyed. Session IDs can never +be updated, they can only be generated when a new session is created.</p> + +<p>In order to store sessions, you must first create a database table for this purpose. Here is the basic +prototype (for MySQL) required by the session class:</p> + +<textarea class="textarea" style="width:100%" cols="50" rows="8"> +CREATE TABLE IF NOT EXISTS `ci_sessions` ( +session_id varchar(40) DEFAULT '0' NOT NULL, +ip_address varchar(16) DEFAULT '0' NOT NULL, +user_agent varchar(50) NOT NULL, +last_activity int(10) unsigned DEFAULT 0 NOT NULL, +user_data text NOT NULL, +PRIMARY KEY (session_id) +);</textarea> + +<p><strong>Note:</strong> By default the table is called <dfn>ci_sessions</dfn>, but you can name it anything you want +as long as you update the <kbd>application/config/config.php</kbd> file so that it contains the name you have chosen. +Once you have created your database table you can enable the database option in your config.php file as follows:</p> + +<code>$config['sess_use_database'] = TRUE;</code> + +<p>Once enabled, the Session class will store session data in the DB.</p> + +<p>Make sure you've specified the table name in your config file as well:</p> + +<code>$config['sess_table_name'] = 'ci_sessions";</code> + +<p class="important"><strong>Note:</strong> The Session class has built-in garbage collection which clears out expired sessions so you +do not need to write your own routine to do it.</p> + + +<h2>Destroying a Session </h2> +<p>To clear the current session: </p> +<code>$this->session->sess_destroy();</code> +<p class="important"><strong>Note:</strong> This function should be the last one called, and even flash variables will no longer be available. If you only want some items destroyed and not all, use <dfn>unset_userdata()</dfn>.</p> + + + +<h2>Session Preferences</h2> +<p>You'll find the following Session related preferences in your <kbd>application/config/config.php</kbd> file:</p> + + +<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder"> +<tr> + <th>Preference</th> + <th>Default</th> + <th>Options</th> + <th>Description</th> +</tr> +<tr> + <td class="td"><strong>sess_cookie_name</strong></td> + <td class="td">ci_session</td> + <td class="td">None</td> + <td class="td">The name you want the session cookie saved as.</td> +</tr> +<tr> + <td class="td"><strong>sess_expiration</strong></td> + <td class="td">7200</td> + <td class="td">None</td> + <td class="td">The number of seconds you would like the session to last. The default value is 2 hours (7200 seconds). If you would like a non-expiring session set the value to zero: 0</td> +</tr> +<tr> + <td class="td"><strong>sess_encrypt_cookie</strong></td> + <td class="td">FALSE</td> + <td class="td">TRUE/FALSE (boolean)</td> + <td class="td">Whether to encrypt the session data.</td> +</tr> +<tr> + <td class="td"><strong>sess_use_database</strong></td> + <td class="td">FALSE</td> + <td class="td">TRUE/FALSE (boolean)</td> + <td class="td">Whether to save the session data to a database. You must create the table before enabling this option.</td> +</tr> +<tr> + <td class="td"><strong>sess_table_name</strong></td> + <td class="td">ci_sessions</td> + <td class="td">Any valid SQL table name</td> + <td class="td">The name of the session database table.</td> +</tr> +<tr> + <td class="td"><strong>sess_time_to_update</strong></td> + <td class="td">300</td> + <td class="td">Time in seconds</td> + <td class="td">This options controls how often the session class will regenerate itself and create a new session id.</td> +</tr> +<tr> + <td class="td"><strong>sess_match_ip</strong></td> + <td class="td">FALSE</td> + <td class="td">TRUE/FALSE (boolean)</td> + <td class="td">Whether to match the user's IP address when reading the session data. Note that some ISPs dynamically + changes the IP, so if you want a non-expiring session you will likely set this to FALSE.</td> +</tr> +<tr> + <td class="td"><strong>sess_match_useragent</strong></td> + <td class="td">TRUE</td> + <td class="td">TRUE/FALSE (boolean)</td> + <td class="td">Whether to match the User Agent when reading the session data.</td> +</tr> +</table> + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="pagination.html">Pagination Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="trackback.html">Trackback Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/table.html b/user_guide/libraries/table.html index 7671d2aab..92fcc9c71 100644 --- a/user_guide/libraries/table.html +++ b/user_guide/libraries/table.html @@ -1,292 +1,292 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>HTML Table Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-HTML Table Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>HTML Table Class</h1>
-
-<p>The Table Class provides functions that enable you to auto-generate HTML tables from arrays or database result sets.</p>
-
-<h2>Initializing the Class</h2>
-
-<p>Like most other classes in CodeIgniter, the Table class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
-
-<code>$this->load->library('table');</code>
-<p>Once loaded, the Table library object will be available using: <dfn>$this->table</dfn></p>
-
-
-<h2>Examples</h2>
-
-<p>Here is an example showing how you can create a table from a multi-dimensional array.
-Note that the first array index will become the table heading (or you can set your own headings using the
-<dfn>set_heading()</dfn> function described in the function reference below).</p>
-
-<code>
-$this->load->library('table');<br />
-<br />
-$data = array(<br />
- array('Name', 'Color', 'Size'),<br />
- array('Fred', 'Blue', 'Small'),<br />
- array('Mary', 'Red', 'Large'),<br />
- array('John', 'Green', 'Medium') <br />
- );<br />
-<br />
-echo $this->table->generate($data);
-</code>
-
-<p>Here is an example of a table created from a database query result. The table class will automatically generate the
-headings based on the table names (or you can set your own headings using the <dfn>set_heading()</dfn> function described
-in the function reference below).</p>
-
-<code>
-$this->load->library('table');<br />
-<br />
-$query = $this->db->query("SELECT * FROM my_table");<br />
-<br />
-echo $this->table->generate($query);
-</code>
-
-
-<p>Here is an example showing how you might create a table using discrete parameters:</p>
-
-<code>
-$this->load->library('table');<br />
-<br />
-$this->table->set_heading('Name', 'Color', 'Size');<br />
-<br />
-$this->table->add_row('Fred', 'Blue', 'Small');<br />
-$this->table->add_row('Mary', 'Red', 'Large');<br />
-$this->table->add_row('John', 'Green', 'Medium');<br />
-<br />
-echo $this->table->generate();
-</code>
-
-<p>Here is the same example, except instead of individual parameters, arrays are used:</p>
-
-<code>
-$this->load->library('table');<br />
-<br />
-$this->table->set_heading(array('Name', 'Color', 'Size'));<br />
-<br />
-$this->table->add_row(array('Fred', 'Blue', 'Small'));<br />
-$this->table->add_row(array('Mary', 'Red', 'Large'));<br />
-$this->table->add_row(array('John', 'Green', 'Medium'));<br />
-<br />
-echo $this->table->generate();
-</code>
-
-
-<h2>Changing the Look of Your Table</h2>
-
-<p>The Table Class permits you to set a table template with which you can specify the design of your layout. Here is the template
-prototype:</p>
-
-<code>
-$tmpl = array (<br />
- 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',<br />
-<br />
- 'heading_row_start' => '<tr>',<br />
- 'heading_row_end' => '</tr>',<br />
- 'heading_cell_start' => '<th>',<br />
- 'heading_cell_end' => '</th>',<br />
-<br />
- 'row_start' => '<tr>',<br />
- 'row_end' => '</tr>',<br />
- 'cell_start' => '<td>',<br />
- 'cell_end' => '</td>',<br />
-<br />
- 'row_alt_start' => '<tr>',<br />
- 'row_alt_end' => '</tr>',<br />
- 'cell_alt_start' => '<td>',<br />
- 'cell_alt_end' => '</td>',<br />
-<br />
- 'table_close' => '</table>'<br />
- );<br />
-
-<br />
-$this->table->set_template($tmpl);
-</code>
-
-<p class="important"><strong>Note:</strong> You'll notice there are two sets of "row" blocks in the template. These permit you to create alternating row colors or design elements that alternate with each
-iteration of the row data.</p>
-
-<p>You are NOT required to submit a complete template. If you only need to change parts of the layout you can simply submit those elements.
-In this example, only the table opening tag is being changed:</p>
-
-<code>
-$tmpl = array ( 'table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' );<br />
-
-<br />
-$this->table->set_template($tmpl);
-</code>
-
-<br />
-<h1>Function Reference</h1>
-
-<h2>$this->table->generate()</h2>
-<p>Returns a string containing the generated table. Accepts an optional parameter which can be an array or a database result object.</p>
-
-<h2>$this->table->set_caption()</h2>
-
-<p>Permits you to add a caption to the table.</p>
-
-<code>$this->table->set_caption('Colors');</code>
-
-<h2>$this->table->set_heading()</h2>
-
-<p>Permits you to set the table heading. You can submit an array or discrete params:</p>
-
-<code>$this->table->set_heading('Name', 'Color', 'Size');</code>
-<code>$this->table->set_heading(array('Name', 'Color', 'Size'));</code>
-
-<h2>$this->table->add_row()</h2>
-
-<p>Permits you to add a row to your table. You can submit an array or discrete params:</p>
-
-<code>$this->table->add_row('Blue', 'Red', 'Green');</code>
-<code>$this->table->add_row(array('Blue', 'Red', 'Green'));</code>
-
-
-<h2>$this->table->make_columns()</h2>
-
-<p>This function takes a one-dimensional array as input and creates
-a multi-dimensional array with a depth equal to the number of
-columns desired. This allows a single array with many elements to be
-displayed in a table that has a fixed column count. Consider this example:</p>
-
-<code>
-$list = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve');<br />
-<br />
-$new_list = $this->table->make_columns($list, 3);<br />
-<br />
-$this->table->generate($new_list);<br />
-<br />
-// Generates a table with this prototype<br />
-<br />
-<table border="0" cellpadding="4" cellspacing="0"><br />
-<tr><br />
-<td>one</td><td>two</td><td>three</td><br />
-</tr><tr><br />
-<td>four</td><td>five</td><td>six</td><br />
-</tr><tr><br />
-<td>seven</td><td>eight</td><td>nine</td><br />
-</tr><tr><br />
-<td>ten</td><td>eleven</td><td>twelve</td></tr><br />
-</table></code>
-
-
-
-<h2>$this->table->set_template()</h2>
-
-<p>Permits you to set your template. You can submit a full or partial template.</p>
-
-<code>
-$tmpl = array ( 'table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' );<br />
-
-<br />
-$this->table->set_template($tmpl);
-</code>
-
-
-<h2>$this->table->set_empty()</h2>
-
-<p>Let's you set a default value for use in any table cells that are empty. You might, for example, set a non-breaking space:</p>
-
-<code>
-$this->table->set_empty("&nbsp;");
-</code>
-
-<h2>$this->table->clear()</h2>
-
-<p>Lets you clear the table heading and row data. If you need to show multiple tables with different data you should
-to call this function after each table has been generated to empty the previous table information. Example:</p>
-
-<code>
-$this->load->library('table');<br />
-<br />
-$this->table->set_heading('Name', 'Color', 'Size');<br />
-$this->table->add_row('Fred', 'Blue', 'Small');<br />
-$this->table->add_row('Mary', 'Red', 'Large');<br />
-$this->table->add_row('John', 'Green', 'Medium');<br />
-<br />
-echo $this->table->generate();<br />
-<br />
-<kbd>$this->table->clear();</kbd><br />
-<br />
-$this->table->set_heading('Name', 'Day', 'Delivery');<br />
-$this->table->add_row('Fred', 'Wednesday', 'Express');<br />
-$this->table->add_row('Mary', 'Monday', 'Air');<br />
-$this->table->add_row('John', 'Saturday', 'Overnight');<br />
-<br />
-echo $this->table->generate();
-</code>
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="ftp.html"> FTP Class</a> ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="image_lib.html">Image Manipulation Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>HTML Table Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +HTML Table Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>HTML Table Class</h1> + +<p>The Table Class provides functions that enable you to auto-generate HTML tables from arrays or database result sets.</p> + +<h2>Initializing the Class</h2> + +<p>Like most other classes in CodeIgniter, the Table class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p> + +<code>$this->load->library('table');</code> +<p>Once loaded, the Table library object will be available using: <dfn>$this->table</dfn></p> + + +<h2>Examples</h2> + +<p>Here is an example showing how you can create a table from a multi-dimensional array. +Note that the first array index will become the table heading (or you can set your own headings using the +<dfn>set_heading()</dfn> function described in the function reference below).</p> + +<code> +$this->load->library('table');<br /> +<br /> +$data = array(<br /> + array('Name', 'Color', 'Size'),<br /> + array('Fred', 'Blue', 'Small'),<br /> + array('Mary', 'Red', 'Large'),<br /> + array('John', 'Green', 'Medium') <br /> + );<br /> +<br /> +echo $this->table->generate($data); +</code> + +<p>Here is an example of a table created from a database query result. The table class will automatically generate the +headings based on the table names (or you can set your own headings using the <dfn>set_heading()</dfn> function described +in the function reference below).</p> + +<code> +$this->load->library('table');<br /> +<br /> +$query = $this->db->query("SELECT * FROM my_table");<br /> +<br /> +echo $this->table->generate($query); +</code> + + +<p>Here is an example showing how you might create a table using discrete parameters:</p> + +<code> +$this->load->library('table');<br /> +<br /> +$this->table->set_heading('Name', 'Color', 'Size');<br /> +<br /> +$this->table->add_row('Fred', 'Blue', 'Small');<br /> +$this->table->add_row('Mary', 'Red', 'Large');<br /> +$this->table->add_row('John', 'Green', 'Medium');<br /> +<br /> +echo $this->table->generate(); +</code> + +<p>Here is the same example, except instead of individual parameters, arrays are used:</p> + +<code> +$this->load->library('table');<br /> +<br /> +$this->table->set_heading(array('Name', 'Color', 'Size'));<br /> +<br /> +$this->table->add_row(array('Fred', 'Blue', 'Small'));<br /> +$this->table->add_row(array('Mary', 'Red', 'Large'));<br /> +$this->table->add_row(array('John', 'Green', 'Medium'));<br /> +<br /> +echo $this->table->generate(); +</code> + + +<h2>Changing the Look of Your Table</h2> + +<p>The Table Class permits you to set a table template with which you can specify the design of your layout. Here is the template +prototype:</p> + +<code> +$tmpl = array (<br /> + 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',<br /> +<br /> + 'heading_row_start' => '<tr>',<br /> + 'heading_row_end' => '</tr>',<br /> + 'heading_cell_start' => '<th>',<br /> + 'heading_cell_end' => '</th>',<br /> +<br /> + 'row_start' => '<tr>',<br /> + 'row_end' => '</tr>',<br /> + 'cell_start' => '<td>',<br /> + 'cell_end' => '</td>',<br /> +<br /> + 'row_alt_start' => '<tr>',<br /> + 'row_alt_end' => '</tr>',<br /> + 'cell_alt_start' => '<td>',<br /> + 'cell_alt_end' => '</td>',<br /> +<br /> + 'table_close' => '</table>'<br /> + );<br /> + +<br /> +$this->table->set_template($tmpl); +</code> + +<p class="important"><strong>Note:</strong> You'll notice there are two sets of "row" blocks in the template. These permit you to create alternating row colors or design elements that alternate with each +iteration of the row data.</p> + +<p>You are NOT required to submit a complete template. If you only need to change parts of the layout you can simply submit those elements. +In this example, only the table opening tag is being changed:</p> + +<code> +$tmpl = array ( 'table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' );<br /> + +<br /> +$this->table->set_template($tmpl); +</code> + +<br /> +<h1>Function Reference</h1> + +<h2>$this->table->generate()</h2> +<p>Returns a string containing the generated table. Accepts an optional parameter which can be an array or a database result object.</p> + +<h2>$this->table->set_caption()</h2> + +<p>Permits you to add a caption to the table.</p> + +<code>$this->table->set_caption('Colors');</code> + +<h2>$this->table->set_heading()</h2> + +<p>Permits you to set the table heading. You can submit an array or discrete params:</p> + +<code>$this->table->set_heading('Name', 'Color', 'Size');</code> +<code>$this->table->set_heading(array('Name', 'Color', 'Size'));</code> + +<h2>$this->table->add_row()</h2> + +<p>Permits you to add a row to your table. You can submit an array or discrete params:</p> + +<code>$this->table->add_row('Blue', 'Red', 'Green');</code> +<code>$this->table->add_row(array('Blue', 'Red', 'Green'));</code> + + +<h2>$this->table->make_columns()</h2> + +<p>This function takes a one-dimensional array as input and creates +a multi-dimensional array with a depth equal to the number of +columns desired. This allows a single array with many elements to be +displayed in a table that has a fixed column count. Consider this example:</p> + +<code> +$list = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve');<br /> +<br /> +$new_list = $this->table->make_columns($list, 3);<br /> +<br /> +$this->table->generate($new_list);<br /> +<br /> +// Generates a table with this prototype<br /> +<br /> +<table border="0" cellpadding="4" cellspacing="0"><br /> +<tr><br /> +<td>one</td><td>two</td><td>three</td><br /> +</tr><tr><br /> +<td>four</td><td>five</td><td>six</td><br /> +</tr><tr><br /> +<td>seven</td><td>eight</td><td>nine</td><br /> +</tr><tr><br /> +<td>ten</td><td>eleven</td><td>twelve</td></tr><br /> +</table></code> + + + +<h2>$this->table->set_template()</h2> + +<p>Permits you to set your template. You can submit a full or partial template.</p> + +<code> +$tmpl = array ( 'table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' );<br /> + +<br /> +$this->table->set_template($tmpl); +</code> + + +<h2>$this->table->set_empty()</h2> + +<p>Let's you set a default value for use in any table cells that are empty. You might, for example, set a non-breaking space:</p> + +<code> +$this->table->set_empty("&nbsp;"); +</code> + +<h2>$this->table->clear()</h2> + +<p>Lets you clear the table heading and row data. If you need to show multiple tables with different data you should +to call this function after each table has been generated to empty the previous table information. Example:</p> + +<code> +$this->load->library('table');<br /> +<br /> +$this->table->set_heading('Name', 'Color', 'Size');<br /> +$this->table->add_row('Fred', 'Blue', 'Small');<br /> +$this->table->add_row('Mary', 'Red', 'Large');<br /> +$this->table->add_row('John', 'Green', 'Medium');<br /> +<br /> +echo $this->table->generate();<br /> +<br /> +<kbd>$this->table->clear();</kbd><br /> +<br /> +$this->table->set_heading('Name', 'Day', 'Delivery');<br /> +$this->table->add_row('Fred', 'Wednesday', 'Express');<br /> +$this->table->add_row('Mary', 'Monday', 'Air');<br /> +$this->table->add_row('John', 'Saturday', 'Overnight');<br /> +<br /> +echo $this->table->generate(); +</code> + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="ftp.html"> FTP Class</a> · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="image_lib.html">Image Manipulation Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/trackback.html b/user_guide/libraries/trackback.html index 177ccb065..1c40a4547 100644 --- a/user_guide/libraries/trackback.html +++ b/user_guide/libraries/trackback.html @@ -1,246 +1,246 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Trackback Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Trackback Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>Trackback Class</h1>
-
-<p>The Trackback Class provides functions that enable you to send and receive Trackback data.</p>
-
-
-<p>If you are not familiar with Trackbacks you'll find more information <a href="http://en.wikipedia.org/wiki/Trackback">here</a>.</p>
-
-<h2>Initializing the Class</h2>
-
-<p>Like most other classes in CodeIgniter, the Trackback class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
-
-<code>$this->load->library('trackback');</code>
-<p>Once loaded, the Trackback library object will be available using: <dfn>$this->trackback</dfn></p>
-
-
-<h2>Sending Trackbacks</h2>
-
-<p>A Trackback can be sent from any of your controller functions using code similar to this example:</p>
-
-<code>$this->load->library('trackback');<br />
-<br />
-$tb_data = array(<br />
- 'ping_url' => 'http://example.com/trackback/456',<br />
- 'url' => 'http://www.my-example.com/blog/entry/123',<br />
- 'title' => 'The Title of My Entry',<br />
- 'excerpt' => 'The entry content.',<br />
- 'blog_name' => 'My Blog Name',<br />
- 'charset' => 'utf-8'<br />
- );<br />
-<br />
-if ( ! $this->trackback->send($tb_data))<br />
-{<br />
- echo $this->trackback->display_errors();<br />
-}<br />
-else<br />
-{<br />
- echo 'Trackback was sent!';<br />
-}</code>
-
-<p>Description of array data:</p>
-
-<ul>
-<li><strong>ping_url</strong> - The URL of the site you are sending the Trackback to. You can send Trackbacks to multiple URLs by separating each URL with a comma.</li>
-<li><strong>url</strong> - The URL to YOUR site where the weblog entry can be seen.</li>
-<li><strong>title</strong> - The title of your weblog entry.</li>
-<li><strong>excerpt</strong> - The content of your weblog entry. Note: the Trackback class will automatically send only the first 500 characters of your entry. It will also strip all HTML.</li>
-<li><strong>blog_name</strong> - The name of your weblog.</li>
-<li><strong>charset</strong> - The character encoding your weblog is written in. If omitted, UTF-8 will be used.</li>
-</ul>
-
-<p>The Trackback sending function returns TRUE/FALSE (boolean) on success or failure. If it fails, you can retrieve the error message using:</p>
-
-<code>$this->trackback->display_errors();</code>
-
-
-<h2>Receiving Trackbacks</h2>
-
-<p>Before you can receive Trackbacks you must create a weblog. If you don't have a blog yet there's no point in continuing.</p>
-
-<p>Receiving Trackbacks is a little more complex than sending them, only because you will need a database table in which to store them,
-and you will need to validate the incoming trackback data. You are encouraged to implement a thorough validation process to
-guard against spam and duplicate data. You may also want to limit the number of Trackbacks you allow from a particular IP within
-a given span of time to further curtail spam. The process of receiving a Trackback is quite simple;
-the validation is what takes most of the effort.</p>
-
-<h2>Your Ping URL</h2>
-
-<p>In order to accept Trackbacks you must display a Trackback URL next to each one of your weblog entries. This will be the URL
-that people will use to send you Trackbacks (we will refer to this as your "Ping URL").</p>
-
-<p>Your Ping URL must point to a controller function where your Trackback receiving code is located, and the URL
-must contain the ID number for each particular entry, so that when the Trackback is received you'll be
-able to associate it with a particular entry.</p>
-
-<p>For example, if your controller class is called <dfn>Trackback</dfn>, and the receiving function is called <dfn>receive</dfn>, your
-Ping URLs will look something like this:</p>
-
-<code>http://example.com/index.php/trackback/receive/<samp>entry_id</samp></code>
-
-<p>Where <samp>entry_id</samp> represents the individual ID number for each of your entries.</p>
-
-
-<h2>Creating a Trackback Table</h2>
-
-<p>Before you can receive Trackbacks you must create a table in which to store them. Here is a basic prototype for such a table:</p>
-
-<textarea class="textarea" style="width:100%" cols="50" rows="13">
-CREATE TABLE trackbacks (
- tb_id int(10) unsigned NOT NULL auto_increment,
- entry_id int(10) unsigned NOT NULL default 0,
- url varchar(200) NOT NULL,
- title varchar(100) NOT NULL,
- excerpt text NOT NULL,
- blog_name varchar(100) NOT NULL,
- tb_date int(10) NOT NULL,
- ip_address varchar(16) NOT NULL,
- PRIMARY KEY `tb_id` (`tb_id`),
- KEY `entry_id` (`entry_id`)
-);</textarea>
-
-
-<p>The Trackback specification only requires four pieces of information to be sent in a Trackback (url, title, excerpt, blog_name),
-but to make the data more useful we've added a few more fields in the above table schema (date, IP address, etc.).</p>
-
-<h2>Processing a Trackback</h2>
-
-<p>Here is an example showing how you will receive and process a Trackback. The following
-code is intended for use within the controller function where you expect to receive Trackbacks.</p>
-
-<code>$this->load->library('trackback');<br />
-$this->load->database();<br />
-<br />
-if ($this->uri->segment(3) == FALSE)<br />
-{<br />
- $this->trackback->send_error("Unable to determine the entry ID");<br />
-}<br />
-<br />
-if ( ! $this->trackback->receive())<br />
-{<br />
- $this->trackback->send_error("The Trackback did not contain valid data");<br />
-}<br />
-<br />
-$data = array(<br />
- 'tb_id' => '',<br />
- 'entry_id' => $this->uri->segment(3),<br />
- 'url' => $this->trackback->data('url'),<br />
- 'title' => $this->trackback->data('title'),<br />
- 'excerpt' => $this->trackback->data('excerpt'),<br />
- 'blog_name' => $this->trackback->data('blog_name'),<br />
- 'tb_date' => time(),<br />
- 'ip_address' => $this->input->ip_address()<br />
- );<br />
-<br />
-$sql = $this->db->insert_string('trackbacks', $data);<br />
-$this->db->query($sql);<br />
-<br />
-$this->trackback->send_success();</code>
-
-<h4>Notes:</h4>
-
-<p>The entry ID number is expected in the third segment of your URL. This is based on the URI example we gave earlier:</p>
-
-<code>http://example.com/index.php/trackback/receive/<samp>entry_id</samp></code>
-
-<p>Notice the entry_id is in the third URI segment, which you can retrieve using:</p>
-
-<code>$this->uri->segment(3);</code>
-
-<p>In our Trackback receiving code above, if the third segment is missing, we will issue an error. Without a valid entry ID, there's no
-reason to continue.</p>
-
-<p>The <dfn>$this->trackback->receive()</dfn> function is simply a validation function that looks at the incoming data
-and makes sure it contains the four pieces of data that are required (url, title, excerpt, blog_name).
-It returns TRUE on success and FALSE on failure. If it fails you will issue an error message.</p>
-
-<p>The incoming Trackback data can be retrieved using this function:</p>
-
-<code>$this->trackback->data('<var>item</var>')</code>
-
-<p>Where <var>item</var> represents one of these four pieces of info: url, title, excerpt, or blog_name</p>
-
-<p>If the Trackback data is successfully received, you will issue a success message using:</p>
-
-<code>$this->trackback->send_success();</code>
-
-<p class="important"><strong>Note:</strong> The above code contains no data validation, which you are encouraged to add.</p>
-
-
-
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="sessions.html">Session Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="parser.html">Template Parser Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Trackback Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Trackback Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>Trackback Class</h1> + +<p>The Trackback Class provides functions that enable you to send and receive Trackback data.</p> + + +<p>If you are not familiar with Trackbacks you'll find more information <a href="http://en.wikipedia.org/wiki/Trackback">here</a>.</p> + +<h2>Initializing the Class</h2> + +<p>Like most other classes in CodeIgniter, the Trackback class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p> + +<code>$this->load->library('trackback');</code> +<p>Once loaded, the Trackback library object will be available using: <dfn>$this->trackback</dfn></p> + + +<h2>Sending Trackbacks</h2> + +<p>A Trackback can be sent from any of your controller functions using code similar to this example:</p> + +<code>$this->load->library('trackback');<br /> +<br /> +$tb_data = array(<br /> + 'ping_url' => 'http://example.com/trackback/456',<br /> + 'url' => 'http://www.my-example.com/blog/entry/123',<br /> + 'title' => 'The Title of My Entry',<br /> + 'excerpt' => 'The entry content.',<br /> + 'blog_name' => 'My Blog Name',<br /> + 'charset' => 'utf-8'<br /> + );<br /> +<br /> +if ( ! $this->trackback->send($tb_data))<br /> +{<br /> + echo $this->trackback->display_errors();<br /> +}<br /> +else<br /> +{<br /> + echo 'Trackback was sent!';<br /> +}</code> + +<p>Description of array data:</p> + +<ul> +<li><strong>ping_url</strong> - The URL of the site you are sending the Trackback to. You can send Trackbacks to multiple URLs by separating each URL with a comma.</li> +<li><strong>url</strong> - The URL to YOUR site where the weblog entry can be seen.</li> +<li><strong>title</strong> - The title of your weblog entry.</li> +<li><strong>excerpt</strong> - The content of your weblog entry. Note: the Trackback class will automatically send only the first 500 characters of your entry. It will also strip all HTML.</li> +<li><strong>blog_name</strong> - The name of your weblog.</li> +<li><strong>charset</strong> - The character encoding your weblog is written in. If omitted, UTF-8 will be used.</li> +</ul> + +<p>The Trackback sending function returns TRUE/FALSE (boolean) on success or failure. If it fails, you can retrieve the error message using:</p> + +<code>$this->trackback->display_errors();</code> + + +<h2>Receiving Trackbacks</h2> + +<p>Before you can receive Trackbacks you must create a weblog. If you don't have a blog yet there's no point in continuing.</p> + +<p>Receiving Trackbacks is a little more complex than sending them, only because you will need a database table in which to store them, +and you will need to validate the incoming trackback data. You are encouraged to implement a thorough validation process to +guard against spam and duplicate data. You may also want to limit the number of Trackbacks you allow from a particular IP within +a given span of time to further curtail spam. The process of receiving a Trackback is quite simple; +the validation is what takes most of the effort.</p> + +<h2>Your Ping URL</h2> + +<p>In order to accept Trackbacks you must display a Trackback URL next to each one of your weblog entries. This will be the URL +that people will use to send you Trackbacks (we will refer to this as your "Ping URL").</p> + +<p>Your Ping URL must point to a controller function where your Trackback receiving code is located, and the URL +must contain the ID number for each particular entry, so that when the Trackback is received you'll be +able to associate it with a particular entry.</p> + +<p>For example, if your controller class is called <dfn>Trackback</dfn>, and the receiving function is called <dfn>receive</dfn>, your +Ping URLs will look something like this:</p> + +<code>http://example.com/index.php/trackback/receive/<samp>entry_id</samp></code> + +<p>Where <samp>entry_id</samp> represents the individual ID number for each of your entries.</p> + + +<h2>Creating a Trackback Table</h2> + +<p>Before you can receive Trackbacks you must create a table in which to store them. Here is a basic prototype for such a table:</p> + +<textarea class="textarea" style="width:100%" cols="50" rows="13"> +CREATE TABLE trackbacks ( + tb_id int(10) unsigned NOT NULL auto_increment, + entry_id int(10) unsigned NOT NULL default 0, + url varchar(200) NOT NULL, + title varchar(100) NOT NULL, + excerpt text NOT NULL, + blog_name varchar(100) NOT NULL, + tb_date int(10) NOT NULL, + ip_address varchar(16) NOT NULL, + PRIMARY KEY `tb_id` (`tb_id`), + KEY `entry_id` (`entry_id`) +);</textarea> + + +<p>The Trackback specification only requires four pieces of information to be sent in a Trackback (url, title, excerpt, blog_name), +but to make the data more useful we've added a few more fields in the above table schema (date, IP address, etc.).</p> + +<h2>Processing a Trackback</h2> + +<p>Here is an example showing how you will receive and process a Trackback. The following +code is intended for use within the controller function where you expect to receive Trackbacks.</p> + +<code>$this->load->library('trackback');<br /> +$this->load->database();<br /> +<br /> +if ($this->uri->segment(3) == FALSE)<br /> +{<br /> + $this->trackback->send_error("Unable to determine the entry ID");<br /> +}<br /> +<br /> +if ( ! $this->trackback->receive())<br /> +{<br /> + $this->trackback->send_error("The Trackback did not contain valid data");<br /> +}<br /> +<br /> +$data = array(<br /> + 'tb_id' => '',<br /> + 'entry_id' => $this->uri->segment(3),<br /> + 'url' => $this->trackback->data('url'),<br /> + 'title' => $this->trackback->data('title'),<br /> + 'excerpt' => $this->trackback->data('excerpt'),<br /> + 'blog_name' => $this->trackback->data('blog_name'),<br /> + 'tb_date' => time(),<br /> + 'ip_address' => $this->input->ip_address()<br /> + );<br /> +<br /> +$sql = $this->db->insert_string('trackbacks', $data);<br /> +$this->db->query($sql);<br /> +<br /> +$this->trackback->send_success();</code> + +<h4>Notes:</h4> + +<p>The entry ID number is expected in the third segment of your URL. This is based on the URI example we gave earlier:</p> + +<code>http://example.com/index.php/trackback/receive/<samp>entry_id</samp></code> + +<p>Notice the entry_id is in the third URI segment, which you can retrieve using:</p> + +<code>$this->uri->segment(3);</code> + +<p>In our Trackback receiving code above, if the third segment is missing, we will issue an error. Without a valid entry ID, there's no +reason to continue.</p> + +<p>The <dfn>$this->trackback->receive()</dfn> function is simply a validation function that looks at the incoming data +and makes sure it contains the four pieces of data that are required (url, title, excerpt, blog_name). +It returns TRUE on success and FALSE on failure. If it fails you will issue an error message.</p> + +<p>The incoming Trackback data can be retrieved using this function:</p> + +<code>$this->trackback->data('<var>item</var>')</code> + +<p>Where <var>item</var> represents one of these four pieces of info: url, title, excerpt, or blog_name</p> + +<p>If the Trackback data is successfully received, you will issue a success message using:</p> + +<code>$this->trackback->send_success();</code> + +<p class="important"><strong>Note:</strong> The above code contains no data validation, which you are encouraged to add.</p> + + + + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="sessions.html">Session Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="parser.html">Template Parser Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/typography.html b/user_guide/libraries/typography.html index cd161016a..2c7e06c9c 100644 --- a/user_guide/libraries/typography.html +++ b/user_guide/libraries/typography.html @@ -1,160 +1,160 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Typography Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Typography Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>Typography Class</h1>
-
-<p>The Typography Class provides functions that help you format text.</p>
-
-
-<h2>Initializing the Class</h2>
-
-<p>Like most other classes in CodeIgniter, the Typography class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
-
-<code>$this->load->library('typography');</code>
-<p>Once loaded, the Typography library object will be available using: <dfn>$this->typography</dfn></p>
-
-
-<h2>auto_typography()</h2>
-
-<p>Formats text so that it is semantically and typographically correct HTML. Takes a string as input and returns it with
-the following formatting:</p>
-
-<ul>
-<li>Surrounds paragraphs within <p></p> (looks for double line breaks to identify paragraphs).</li>
-<li>Single line breaks are converted to <br />, except those that appear within <pre> tags.</li>
-<li>Block level elements, like <div> tags, are not wrapped within paragraphs, but their contained text is if it contains paragraphs.</li>
-<li>Quotes are converted to correctly facing curly quote entities, except those that appear within tags.</li>
-<li>Apostrophes are converted to curly apostrophy entities.</li>
-<li>Double dashes (either like -- this or like--this) are converted to em—dashes.</li>
-<li>Three consecutive periods either preceding or following a word are converted to ellipsis…</li>
-<li>Double spaces following sentences are converted to non-breaking spaces to mimic double spacing.</li>
-</ul>
-
-<p>Usage example:</p>
-
-<code>$string = $this->typography->auto_typography($string);</code>
-
-<h3>Parameters</h3>
-
-<p>There is one optional parameters that determines whether the parser should reduce more then two consecutive linebreaks down to two. Use bolean <kbd>TRUE</kbd> or <kbd>FALSE</kbd>.
-
-<p>By default the parser does not reduce line breaks. In other words, if no parameters are submitted, it is the same as doing this:</p>
-
-<code>$string = $this->typography->auto_typography($string, <kbd>FALSE</kbd>);</code>
-
-
-<p class="important"><strong>Note:</strong> Typographic formatting can be processor intensive, particularly if you have a lot of content being formatted.
-If you choose to use this function you may want to consider
-<a href="../general/caching.html">caching</a> your pages.</p>
-
-
-
-<h2>convert_characters()</h2>
-
-<p>This function is similiar to the <dfn>auto_typography</dfn> function above, except that it only does character conversion:</p>
-
-<ul>
-<li>Quotes are converted to correctly facing curly quote entities, except those that appear within tags.</li>
-<li>Apostrophes are converted to curly apostrophy entities.</li>
-<li>Double dashes (either like -- this or like--this) are converted to em—dashes.</li>
-<li>Three consecutive periods either preceding or following a word are converted to ellipsis…</li>
-<li>Double spaces following sentences are converted to non-breaking spaces to mimic double spacing.</li>
-</ul>
-
-<p>Usage example:</p>
-
-<code>$string = $this->typography->convert_characters($string);</code>
-
-
-<h2>nl2br_except_pre()</h2>
-
-<p>Converts newlines to <br /> tags unless they appear within <pre> tags.
-This function is identical to the native PHP <dfn>nl2br()</dfn> function, except that it ignores <pre> tags.</p>
-
-<p>Usage example:</p>
-
-<code>$string = $this->typography->nl2br_except_pre($string);</code>
-
-<h2>protect_braced_quotes</h2>
-
-<p>When using the Typography library in conjunction with the Template Parser library it can often be desirable to protect single
- and double quotes within curly braces. To enable this, set the <kbd>protect_braced_quotes</kbd> class property to <samp>TRUE</samp>.
-
-<p>Usage example:</p>
-
-<code>$this->load->library('typography');<br />
-$this->typography->protect_braced_quotes = TRUE;
-</code>
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="parser.html">Template Parser</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="unit_testing.html">Unit Testing Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Typography Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Typography Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>Typography Class</h1> + +<p>The Typography Class provides functions that help you format text.</p> + + +<h2>Initializing the Class</h2> + +<p>Like most other classes in CodeIgniter, the Typography class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p> + +<code>$this->load->library('typography');</code> +<p>Once loaded, the Typography library object will be available using: <dfn>$this->typography</dfn></p> + + +<h2>auto_typography()</h2> + +<p>Formats text so that it is semantically and typographically correct HTML. Takes a string as input and returns it with +the following formatting:</p> + +<ul> +<li>Surrounds paragraphs within <p></p> (looks for double line breaks to identify paragraphs).</li> +<li>Single line breaks are converted to <br />, except those that appear within <pre> tags.</li> +<li>Block level elements, like <div> tags, are not wrapped within paragraphs, but their contained text is if it contains paragraphs.</li> +<li>Quotes are converted to correctly facing curly quote entities, except those that appear within tags.</li> +<li>Apostrophes are converted to curly apostrophy entities.</li> +<li>Double dashes (either like -- this or like--this) are converted to em—dashes.</li> +<li>Three consecutive periods either preceding or following a word are converted to ellipsis…</li> +<li>Double spaces following sentences are converted to non-breaking spaces to mimic double spacing.</li> +</ul> + +<p>Usage example:</p> + +<code>$string = $this->typography->auto_typography($string);</code> + +<h3>Parameters</h3> + +<p>There is one optional parameters that determines whether the parser should reduce more then two consecutive linebreaks down to two. Use bolean <kbd>TRUE</kbd> or <kbd>FALSE</kbd>. + +<p>By default the parser does not reduce line breaks. In other words, if no parameters are submitted, it is the same as doing this:</p> + +<code>$string = $this->typography->auto_typography($string, <kbd>FALSE</kbd>);</code> + + +<p class="important"><strong>Note:</strong> Typographic formatting can be processor intensive, particularly if you have a lot of content being formatted. +If you choose to use this function you may want to consider +<a href="../general/caching.html">caching</a> your pages.</p> + + + +<h2>convert_characters()</h2> + +<p>This function is similiar to the <dfn>auto_typography</dfn> function above, except that it only does character conversion:</p> + +<ul> +<li>Quotes are converted to correctly facing curly quote entities, except those that appear within tags.</li> +<li>Apostrophes are converted to curly apostrophy entities.</li> +<li>Double dashes (either like -- this or like--this) are converted to em—dashes.</li> +<li>Three consecutive periods either preceding or following a word are converted to ellipsis…</li> +<li>Double spaces following sentences are converted to non-breaking spaces to mimic double spacing.</li> +</ul> + +<p>Usage example:</p> + +<code>$string = $this->typography->convert_characters($string);</code> + + +<h2>nl2br_except_pre()</h2> + +<p>Converts newlines to <br /> tags unless they appear within <pre> tags. +This function is identical to the native PHP <dfn>nl2br()</dfn> function, except that it ignores <pre> tags.</p> + +<p>Usage example:</p> + +<code>$string = $this->typography->nl2br_except_pre($string);</code> + +<h2>protect_braced_quotes</h2> + +<p>When using the Typography library in conjunction with the Template Parser library it can often be desirable to protect single + and double quotes within curly braces. To enable this, set the <kbd>protect_braced_quotes</kbd> class property to <samp>TRUE</samp>. + +<p>Usage example:</p> + +<code>$this->load->library('typography');<br /> +$this->typography->protect_braced_quotes = TRUE; +</code> + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="parser.html">Template Parser</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="unit_testing.html">Unit Testing Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/unit_testing.html b/user_guide/libraries/unit_testing.html index 376323272..35bd347fb 100644 --- a/user_guide/libraries/unit_testing.html +++ b/user_guide/libraries/unit_testing.html @@ -1,205 +1,205 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Unit Testing Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Unit Testing Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>Unit Testing Class</h1>
-
-<p>Unit testing is an approach to software development in which tests are written for each function in your application.
-If you are not familiar with the concept you might do a little googling on the subject.</p>
-
-<p>CodeIgniter's Unit Test class is quite simple, consisting of an evaluation function and two result functions.
-It's not intended to be a full-blown test suite but rather a simple mechanism to evaluate your code
-to determine if it is producing the correct data type and result.
-</p>
-
-
-<h2>Initializing the Class</h2>
-
-<p>Like most other classes in CodeIgniter, the Unit Test class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
-
-<code>$this->load->library('unit_test');</code>
-<p>Once loaded, the Unit Test object will be available using: <dfn>$this->unit</dfn></p>
-
-
-<h2>Running Tests</h2>
-
-<p>Running a test involves supplying a test and an expected result to the following function:</p>
-
-<h2>$this->unit->run( <var>test</var>, <var>expected result</var>, '<var>test name</var>' );</h2>
-
-<p>Where <var>test</var> is the result of the code you wish to test,
-<var>expected result</var> is the data type you expect, and <var>test name</var> is an optional name you can give your test. Example:</p>
-
-<code>$test = 1 + 1;<br />
-<br />
-$expected_result = 2;<br />
-<br />
-$test_name = 'Adds one plus one';<br />
-<br />
-$this->unit->run($test, $expected_result, $test_name);</code>
-
-<p>The expected result you supply can either be a literal match, or a data type match. Here's an example of a literal:</p>
-
-<code>$this->unit->run('Foo', 'Foo');</code>
-
-<p>Here is an example of a data type match:</p>
-
-<code>$this->unit->run('Foo', 'is_string');</code>
-
-<p>Notice the use of "is_string" in the second parameter? This tells the function to evaluate whether your test is producing a string
-as the result. Here is a list of allowed comparison types:</p>
-
-<ul>
-<li>is_string</li>
-<li>is_bool</li>
-<li>is_true</li>
-<li>is_false</li>
-<li>is_int</li>
-<li>is_numeric</li>
-<li>is_float</li>
-<li>is_double</li>
-<li>is_array</li>
-<li>is_null</li>
-</ul>
-
-
-<h2>Generating Reports</h2>
-
-<p>You can either display results after each test, or your can run several tests and generate a report at the end.
-To show a report directly simply echo or return the <var>run</var> function:</p>
-
-<code>echo $this->unit->run($test, $expected_result);</code>
-
-<p>To run a full report of all tests, use this:</p>
-
-<code>echo $this->unit->report();</code>
-
-<p>The report will be formatted in an HTML table for viewing. If you prefer the raw data you can retrieve an array using:</p>
-
-<code>echo $this->unit->result();</code>
-
-
-<h2>Strict Mode</h2>
-
-<p>By default the unit test class evaluates literal matches loosely. Consider this example:</p>
-
-<code>$this->unit->run(1, TRUE);</code>
-
-<p>The test is evaluating an integer, but the expected result is a boolean. PHP, however, due to it's loose data-typing
-will evaluate the above code as TRUE using a normal equality test:</p>
-
-<code>if (1 == TRUE) echo 'This evaluates as true';</code>
-
-<p>If you prefer, you can put the unit test class in to strict mode, which will compare the data type as well as the value:</p>
-
-<code>if (1 === TRUE) echo 'This evaluates as FALSE';</code>
-
-<p>To enable strict mode use this:</p>
-
-<code>$this->unit->use_strict(TRUE);</code>
-
-<h2>Enabling/Disabling Unit Testing</h2>
-
-<p>If you would like to leave some testing in place in your scripts, but not have it run unless you need it, you can disable
-unit testing using:</p>
-
-<code>$this->unit->active(FALSE)</code>
-
-
-
-<h2>Creating a Template</h2>
-
-<p>If you would like your test results formatted differently then the default you can set your own template. Here is an
-example of a simple template. Note the required pseudo-variables:</p>
-
-<code>
-$str = '<br />
-<table border="0" cellpadding="4" cellspacing="1"><br />
- <kbd>{rows}</kbd><br />
- <tr><br />
- <td><kbd>{item}</kbd></td><br />
- <td><kbd>{result}</kbd></td><br />
- </tr><br />
- <kbd>{/rows}</kbd><br />
-</table>';<br />
-<br />
-$this->unit->set_template($str);
-</code>
-
-<p class="important"><strong>Note:</strong> Your template must be declared <strong>before</strong> running the unit test process.</p>
-
-
-
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="typography.html">Typography Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="uri.html">URI Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Unit Testing Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Unit Testing Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>Unit Testing Class</h1> + +<p>Unit testing is an approach to software development in which tests are written for each function in your application. +If you are not familiar with the concept you might do a little googling on the subject.</p> + +<p>CodeIgniter's Unit Test class is quite simple, consisting of an evaluation function and two result functions. +It's not intended to be a full-blown test suite but rather a simple mechanism to evaluate your code +to determine if it is producing the correct data type and result. +</p> + + +<h2>Initializing the Class</h2> + +<p>Like most other classes in CodeIgniter, the Unit Test class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p> + +<code>$this->load->library('unit_test');</code> +<p>Once loaded, the Unit Test object will be available using: <dfn>$this->unit</dfn></p> + + +<h2>Running Tests</h2> + +<p>Running a test involves supplying a test and an expected result to the following function:</p> + +<h2>$this->unit->run( <var>test</var>, <var>expected result</var>, '<var>test name</var>' );</h2> + +<p>Where <var>test</var> is the result of the code you wish to test, +<var>expected result</var> is the data type you expect, and <var>test name</var> is an optional name you can give your test. Example:</p> + +<code>$test = 1 + 1;<br /> +<br /> +$expected_result = 2;<br /> +<br /> +$test_name = 'Adds one plus one';<br /> +<br /> +$this->unit->run($test, $expected_result, $test_name);</code> + +<p>The expected result you supply can either be a literal match, or a data type match. Here's an example of a literal:</p> + +<code>$this->unit->run('Foo', 'Foo');</code> + +<p>Here is an example of a data type match:</p> + +<code>$this->unit->run('Foo', 'is_string');</code> + +<p>Notice the use of "is_string" in the second parameter? This tells the function to evaluate whether your test is producing a string +as the result. Here is a list of allowed comparison types:</p> + +<ul> +<li>is_string</li> +<li>is_bool</li> +<li>is_true</li> +<li>is_false</li> +<li>is_int</li> +<li>is_numeric</li> +<li>is_float</li> +<li>is_double</li> +<li>is_array</li> +<li>is_null</li> +</ul> + + +<h2>Generating Reports</h2> + +<p>You can either display results after each test, or your can run several tests and generate a report at the end. +To show a report directly simply echo or return the <var>run</var> function:</p> + +<code>echo $this->unit->run($test, $expected_result);</code> + +<p>To run a full report of all tests, use this:</p> + +<code>echo $this->unit->report();</code> + +<p>The report will be formatted in an HTML table for viewing. If you prefer the raw data you can retrieve an array using:</p> + +<code>echo $this->unit->result();</code> + + +<h2>Strict Mode</h2> + +<p>By default the unit test class evaluates literal matches loosely. Consider this example:</p> + +<code>$this->unit->run(1, TRUE);</code> + +<p>The test is evaluating an integer, but the expected result is a boolean. PHP, however, due to it's loose data-typing +will evaluate the above code as TRUE using a normal equality test:</p> + +<code>if (1 == TRUE) echo 'This evaluates as true';</code> + +<p>If you prefer, you can put the unit test class in to strict mode, which will compare the data type as well as the value:</p> + +<code>if (1 === TRUE) echo 'This evaluates as FALSE';</code> + +<p>To enable strict mode use this:</p> + +<code>$this->unit->use_strict(TRUE);</code> + +<h2>Enabling/Disabling Unit Testing</h2> + +<p>If you would like to leave some testing in place in your scripts, but not have it run unless you need it, you can disable +unit testing using:</p> + +<code>$this->unit->active(FALSE)</code> + + + +<h2>Creating a Template</h2> + +<p>If you would like your test results formatted differently then the default you can set your own template. Here is an +example of a simple template. Note the required pseudo-variables:</p> + +<code> +$str = '<br /> +<table border="0" cellpadding="4" cellspacing="1"><br /> + <kbd>{rows}</kbd><br /> + <tr><br /> + <td><kbd>{item}</kbd></td><br /> + <td><kbd>{result}</kbd></td><br /> + </tr><br /> + <kbd>{/rows}</kbd><br /> +</table>';<br /> +<br /> +$this->unit->set_template($str); +</code> + +<p class="important"><strong>Note:</strong> Your template must be declared <strong>before</strong> running the unit test process.</p> + + + + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="typography.html">Typography Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="uri.html">URI Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/uri.html b/user_guide/libraries/uri.html index 7bebbf386..fb8deb253 100644 --- a/user_guide/libraries/uri.html +++ b/user_guide/libraries/uri.html @@ -1,252 +1,252 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>URI Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-URI Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>URI Class</h1>
-
-<p>The URI Class provides functions that help you retrieve information from your URI strings. If you use URI routing, you can
-also retrieve information about the re-routed segments.</p>
-
-<p class="important"><strong>Note:</strong> This class is initialized automatically by the system so there is no need to do it manually.</p>
-
-<h2>$this->uri->segment(<var>n</var>)</h2>
-
-<p>Permits you to retrieve a specific segment. Where <var>n</var> is the segment number you wish to retrieve.
-Segments are numbered from left to right. For example, if your full URL is this:</p>
-
-<code>http://example.com/index.php/news/local/metro/crime_is_up</code>
-
-<p>The segment numbers would be this:</p>
-
-<ol>
-<li>news</li>
-<li>local</li>
-<li>metro</li>
-<li>crime_is_up</li>
-</ol>
-
-<p>By default the function returns FALSE (boolean) if the segment does not exist. There is an optional second parameter that
-permits you to set your own default value if the segment is missing.
-For example, this would tell the function to return the number zero in the event of failure:</p>
-
-<code>$product_id = $this->uri->segment(3, 0);</code>
-
-<p>It helps avoid having to write code like this:</p>
-
-<code>if ($this->uri->segment(3) === FALSE)<br />
-{<br />
- $product_id = 0;<br />
-}<br />
-else<br />
-{<br />
- $product_id = $this->uri->segment(3);<br />
-}<br />
-</code>
-
-<h2>$this->uri->rsegment(<var>n</var>)</h2>
-
-<p>This function is identical to the previous one, except that it lets you retrieve a specific segment from your
-re-routed URI in the event you are using CodeIgniter's <a href="../general/routing.html">URI Routing</a> feature.</p>
-
-
-<h2>$this->uri->slash_segment(<var>n</var>)</h2>
-
-<p>This function is almost identical to <dfn>$this->uri->segment()</dfn>, except it adds a trailing and/or leading slash based on the second
-parameter. If the parameter is not used, a trailing slash added. Examples:</p>
-
-<code>$this->uri->slash_segment(<var>3</var>);<br />
-$this->uri->slash_segment(<var>3</var>, 'leading');<br />
-$this->uri->slash_segment(<var>3</var>, 'both');</code>
-
-<p>Returns:</p>
-
-<ol>
-<li>segment/</li>
-<li>/segment</li>
-<li>/segment/</li>
-</ol>
-
-
-<h2>$this->uri->slash_rsegment(<var>n</var>)</h2>
-
-<p>This function is identical to the previous one, except that it lets you add slashes a specific segment from your
-re-routed URI in the event you are using CodeIgniter's <a href="../general/routing.html">URI Routing</a> feature.</p>
-
-
-
-<h2>$this->uri->uri_to_assoc(<var>n</var>)</h2>
-
-<p>This function lets you turn URI segments into and associative array of key/value pairs. Consider this URI:</p>
-
-<code>index.php/user/search/name/joe/location/UK/gender/male</code>
-
-<p>Using this function you can turn the URI into an associative array with this prototype:</p>
-
-<code>[array]<br />
-(<br />
- 'name' => 'joe'<br />
- 'location' => 'UK'<br />
- 'gender' => 'male'<br />
-)</code>
-
-<p>The first parameter of the function lets you set an offset. By default it is set to <kbd>3</kbd> since your
-URI will normally contain a controller/function in the first and second segments. Example:</p>
-
-<code>
-$array = $this->uri->uri_to_assoc(3);<br />
-<br />
-echo $array['name'];
-</code>
-
-
-<p>The second parameter lets you set default key names, so that the array returned by the function will always contain expected indexes, even if missing from the URI. Example:</p>
-
-<code>
-$default = array('name', 'gender', 'location', 'type', 'sort');<br />
-<br />
-$array = $this->uri->uri_to_assoc(3, $default);</code>
-
-<p>If the URI does not contain a value in your default, an array index will be set to that name, with a value of FALSE.</p>
-
-<p>Lastly, if a corresponding value is not found for a given key (if there is an odd number of URI segments) the value will be set to FALSE (boolean).</p>
-
-
-<h2>$this->uri->ruri_to_assoc(<var>n</var>)</h2>
-
-<p>This function is identical to the previous one, except that it creates an associative array using the
-re-routed URI in the event you are using CodeIgniter's <a href="../general/routing.html">URI Routing</a> feature.</p>
-
-
-<h2>$this->uri->assoc_to_uri()</h2>
-
-<p>Takes an associative array as input and generates a URI string from it. The array keys will be included in the string. Example:</p>
-
-<code>$array = array('product' => 'shoes', 'size' => 'large', 'color' => 'red');<br />
-<br />
-$str = $this->uri->assoc_to_uri($array);<br />
-<br />
-// Produces: product/shoes/size/large/color/red
-</code>
-
-
-<h2>$this->uri->uri_string()</h2>
-
-<p>Returns a string with the complete URI. For example, if this is your full URL:</p>
-
-<code>http://example.com/index.php/news/local/345</code>
-
-<p>The function would return this:</p>
-
-<code>/news/local/345</code>
-
-
-<h2>$this->uri->ruri_string(<var>n</var>)</h2>
-
-<p>This function is identical to the previous one, except that it returns the
-re-routed URI in the event you are using CodeIgniter's <a href="../general/routing.html">URI Routing</a> feature.</p>
-
-
-
-<h2>$this->uri->total_segments()</h2>
-
-<p>Returns the total number of segments.</p>
-
-
-<h2>$this->uri->total_rsegments()</h2>
-
-<p>This function is identical to the previous one, except that it returns the total number of segments in your
-re-routed URI in the event you are using CodeIgniter's <a href="../general/routing.html">URI Routing</a> feature.</p>
-
-
-
-<h2>$this->uri->segment_array()</h2>
-
-<p>Returns an array containing the URI segments. For example:</p>
-
-<code>
-$segs = $this->uri->segment_array();<br />
-<br />
-foreach ($segs as $segment)<br />
-{<br />
- echo $segment;<br />
- echo '<br />';<br />
-}</code>
-
-<h2>$this->uri->rsegment_array()</h2>
-
-<p>This function is identical to the previous one, except that it returns the array of segments in your
-re-routed URI in the event you are using CodeIgniter's <a href="../general/routing.html">URI Routing</a> feature.</p>
-
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="unit_testing.html">Unit Testing Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="user_agent.html">User Agent Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>URI Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +URI Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>URI Class</h1> + +<p>The URI Class provides functions that help you retrieve information from your URI strings. If you use URI routing, you can +also retrieve information about the re-routed segments.</p> + +<p class="important"><strong>Note:</strong> This class is initialized automatically by the system so there is no need to do it manually.</p> + +<h2>$this->uri->segment(<var>n</var>)</h2> + +<p>Permits you to retrieve a specific segment. Where <var>n</var> is the segment number you wish to retrieve. +Segments are numbered from left to right. For example, if your full URL is this:</p> + +<code>http://example.com/index.php/news/local/metro/crime_is_up</code> + +<p>The segment numbers would be this:</p> + +<ol> +<li>news</li> +<li>local</li> +<li>metro</li> +<li>crime_is_up</li> +</ol> + +<p>By default the function returns FALSE (boolean) if the segment does not exist. There is an optional second parameter that +permits you to set your own default value if the segment is missing. +For example, this would tell the function to return the number zero in the event of failure:</p> + +<code>$product_id = $this->uri->segment(3, 0);</code> + +<p>It helps avoid having to write code like this:</p> + +<code>if ($this->uri->segment(3) === FALSE)<br /> +{<br /> + $product_id = 0;<br /> +}<br /> +else<br /> +{<br /> + $product_id = $this->uri->segment(3);<br /> +}<br /> +</code> + +<h2>$this->uri->rsegment(<var>n</var>)</h2> + +<p>This function is identical to the previous one, except that it lets you retrieve a specific segment from your +re-routed URI in the event you are using CodeIgniter's <a href="../general/routing.html">URI Routing</a> feature.</p> + + +<h2>$this->uri->slash_segment(<var>n</var>)</h2> + +<p>This function is almost identical to <dfn>$this->uri->segment()</dfn>, except it adds a trailing and/or leading slash based on the second +parameter. If the parameter is not used, a trailing slash added. Examples:</p> + +<code>$this->uri->slash_segment(<var>3</var>);<br /> +$this->uri->slash_segment(<var>3</var>, 'leading');<br /> +$this->uri->slash_segment(<var>3</var>, 'both');</code> + +<p>Returns:</p> + +<ol> +<li>segment/</li> +<li>/segment</li> +<li>/segment/</li> +</ol> + + +<h2>$this->uri->slash_rsegment(<var>n</var>)</h2> + +<p>This function is identical to the previous one, except that it lets you add slashes a specific segment from your +re-routed URI in the event you are using CodeIgniter's <a href="../general/routing.html">URI Routing</a> feature.</p> + + + +<h2>$this->uri->uri_to_assoc(<var>n</var>)</h2> + +<p>This function lets you turn URI segments into and associative array of key/value pairs. Consider this URI:</p> + +<code>index.php/user/search/name/joe/location/UK/gender/male</code> + +<p>Using this function you can turn the URI into an associative array with this prototype:</p> + +<code>[array]<br /> +(<br /> + 'name' => 'joe'<br /> + 'location' => 'UK'<br /> + 'gender' => 'male'<br /> +)</code> + +<p>The first parameter of the function lets you set an offset. By default it is set to <kbd>3</kbd> since your +URI will normally contain a controller/function in the first and second segments. Example:</p> + +<code> +$array = $this->uri->uri_to_assoc(3);<br /> +<br /> +echo $array['name']; +</code> + + +<p>The second parameter lets you set default key names, so that the array returned by the function will always contain expected indexes, even if missing from the URI. Example:</p> + +<code> +$default = array('name', 'gender', 'location', 'type', 'sort');<br /> +<br /> +$array = $this->uri->uri_to_assoc(3, $default);</code> + +<p>If the URI does not contain a value in your default, an array index will be set to that name, with a value of FALSE.</p> + +<p>Lastly, if a corresponding value is not found for a given key (if there is an odd number of URI segments) the value will be set to FALSE (boolean).</p> + + +<h2>$this->uri->ruri_to_assoc(<var>n</var>)</h2> + +<p>This function is identical to the previous one, except that it creates an associative array using the +re-routed URI in the event you are using CodeIgniter's <a href="../general/routing.html">URI Routing</a> feature.</p> + + +<h2>$this->uri->assoc_to_uri()</h2> + +<p>Takes an associative array as input and generates a URI string from it. The array keys will be included in the string. Example:</p> + +<code>$array = array('product' => 'shoes', 'size' => 'large', 'color' => 'red');<br /> +<br /> +$str = $this->uri->assoc_to_uri($array);<br /> +<br /> +// Produces: product/shoes/size/large/color/red +</code> + + +<h2>$this->uri->uri_string()</h2> + +<p>Returns a string with the complete URI. For example, if this is your full URL:</p> + +<code>http://example.com/index.php/news/local/345</code> + +<p>The function would return this:</p> + +<code>/news/local/345</code> + + +<h2>$this->uri->ruri_string(<var>n</var>)</h2> + +<p>This function is identical to the previous one, except that it returns the +re-routed URI in the event you are using CodeIgniter's <a href="../general/routing.html">URI Routing</a> feature.</p> + + + +<h2>$this->uri->total_segments()</h2> + +<p>Returns the total number of segments.</p> + + +<h2>$this->uri->total_rsegments()</h2> + +<p>This function is identical to the previous one, except that it returns the total number of segments in your +re-routed URI in the event you are using CodeIgniter's <a href="../general/routing.html">URI Routing</a> feature.</p> + + + +<h2>$this->uri->segment_array()</h2> + +<p>Returns an array containing the URI segments. For example:</p> + +<code> +$segs = $this->uri->segment_array();<br /> +<br /> +foreach ($segs as $segment)<br /> +{<br /> + echo $segment;<br /> + echo '<br />';<br /> +}</code> + +<h2>$this->uri->rsegment_array()</h2> + +<p>This function is identical to the previous one, except that it returns the array of segments in your +re-routed URI in the event you are using CodeIgniter's <a href="../general/routing.html">URI Routing</a> feature.</p> + + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="unit_testing.html">Unit Testing Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="user_agent.html">User Agent Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/user_agent.html b/user_guide/libraries/user_agent.html index 0a0126084..39337dbd3 100644 --- a/user_guide/libraries/user_agent.html +++ b/user_guide/libraries/user_agent.html @@ -1,201 +1,201 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>User Agent Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-User Agent Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>User Agent Class</h1>
-
-<p>The User Agent Class provides functions that help identify information about the browser, mobile device, or robot visiting your site.
-In addition you can get referrer information as well as language and supported character-set information.</p>
-
-<h2>Initializing the Class</h2>
-
-<p>Like most other classes in CodeIgniter, the User Agent class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
-
-<code>$this->load->library('user_agent');</code>
-<p>Once loaded, the object will be available using: <dfn>$this->agent</dfn></p>
-
-<h2>User Agent Definitions</h2>
-
-<p>The user agent name definitions are located in a config file located at: <dfn>application/config/user_agents.php</dfn>. You may add items to the
-various user agent arrays if needed.</p>
-
-<h2>Example</h2>
-
-<p>When the User Agent class is initialized it will attempt to determine whether the user agent browsing your site is
-a web browser, a mobile device, or a robot. It will also gather the platform information if it is available.</p>
-
-
-<code>
-$this->load->library('user_agent');<br />
-<br />
-if ($this->agent->is_browser())<br />
-{<br />
- $agent = $this->agent->browser().' '.$this->agent->version();<br />
-}<br />
-elseif ($this->agent->is_robot())<br />
-{<br />
- $agent = $this->agent->robot();<br />
-}<br />
-elseif ($this->agent->is_mobile())<br />
-{<br />
- $agent = $this->agent->mobile();<br />
-}<br />
-else<br />
-{<br />
- $agent = 'Unidentified User Agent';<br />
-}<br />
-<br />
-echo $agent;<br />
-<br />
-echo $this->agent->platform(); // Platform info (Windows, Linux, Mac, etc.)
-</code>
-
-
-<h1>Function Reference</h1>
-
-
-<h2>$this->agent->is_browser()</h2>
-<p>Returns TRUE/FALSE (boolean) if the user agent is a known web browser.</p>
-
-<h2>$this->agent->is_mobile()</h2>
-<p>Returns TRUE/FALSE (boolean) if the user agent is a known mobile device.</p>
-
-<h2>$this->agent->is_robot()</h2>
-<p>Returns TRUE/FALSE (boolean) if the user agent is a known robot.</p>
-
-<p class="important"><strong>Note:</strong> The user agent library only contains the most common robot
-definitions. It is not a complete list of bots. There are hundreds of them so searching for each one would not be
-very efficient. If you find that some bots that commonly visit your site are missing from the list you can add them to your
-<dfn>application/config/user_agents.php</dfn> file.</p>
-
-<h2>$this->agent->is_referral()</h2>
-<p>Returns TRUE/FALSE (boolean) if the user agent was referred from another site.</p>
-
-
-<h2>$this->agent->browser()</h2>
-<p>Returns a string containing the name of the web browser viewing your site.</p>
-
-<h2>$this->agent->version()</h2>
-<p>Returns a string containing the version number of the web browser viewing your site.</p>
-
-<h2>$this->agent->mobile()</h2>
-<p>Returns a string containing the name of the mobile device viewing your site.</p>
-
-<h2>$this->agent->robot()</h2>
-<p>Returns a string containing the name of the robot viewing your site.</p>
-
-<h2>$this->agent->platform()</h2>
-<p>Returns a string containing the platform viewing your site (Linux, Windows, OS X, etc.).</p>
-
-<h2>$this->agent->referrer()</h2>
-<p>The referrer, if the user agent was referred from another site. Typically you'll test for this as follows:</p>
-
-<code> if ($this->agent->is_referral())<br />
-{<br />
- echo $this->agent->referrer();<br />
-}</code>
-
-
-<h2>$this->agent->agent_string()</h2>
-<p>Returns a string containing the full user agent string. Typically it will be something like this:</p>
-
-<code>Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.0.4) Gecko/20060613 Camino/1.0.2</code>
-
-
-<h2>$this->agent->accept_lang()</h2>
-<p>Lets you determine if the user agent accepts a particular language. Example:</p>
-
-<code>if ($this->agent->accept_lang('en'))<br />
-{<br />
- echo 'You accept English!';<br />
-}</code>
-
-<p class="important"><strong>Note:</strong> This function is not typically very reliable
-since some browsers do not provide language info, and even among those that do, it is not always accurate. </p>
-
-
-
-<h2>$this->agent->accept_charset()</h2>
-<p>Lets you determine if the user agent accepts a particular character set. Example:</p>
-
-<code>if ($this->agent->accept_charset('utf-8'))<br />
-{<br />
- echo 'You browser supports UTF-8!';<br />
-}</code>
-
-<p class="important"><strong>Note:</strong> This function is not typically very reliable
-since some browsers do not provide character-set info, and even among those that do, it is not always accurate. </p>
-
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="uri.html">URI Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="xmlrpc.html">XML-RPC Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>User Agent Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +User Agent Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>User Agent Class</h1> + +<p>The User Agent Class provides functions that help identify information about the browser, mobile device, or robot visiting your site. +In addition you can get referrer information as well as language and supported character-set information.</p> + +<h2>Initializing the Class</h2> + +<p>Like most other classes in CodeIgniter, the User Agent class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p> + +<code>$this->load->library('user_agent');</code> +<p>Once loaded, the object will be available using: <dfn>$this->agent</dfn></p> + +<h2>User Agent Definitions</h2> + +<p>The user agent name definitions are located in a config file located at: <dfn>application/config/user_agents.php</dfn>. You may add items to the +various user agent arrays if needed.</p> + +<h2>Example</h2> + +<p>When the User Agent class is initialized it will attempt to determine whether the user agent browsing your site is +a web browser, a mobile device, or a robot. It will also gather the platform information if it is available.</p> + + +<code> +$this->load->library('user_agent');<br /> +<br /> +if ($this->agent->is_browser())<br /> +{<br /> + $agent = $this->agent->browser().' '.$this->agent->version();<br /> +}<br /> +elseif ($this->agent->is_robot())<br /> +{<br /> + $agent = $this->agent->robot();<br /> +}<br /> +elseif ($this->agent->is_mobile())<br /> +{<br /> + $agent = $this->agent->mobile();<br /> +}<br /> +else<br /> +{<br /> + $agent = 'Unidentified User Agent';<br /> +}<br /> +<br /> +echo $agent;<br /> +<br /> +echo $this->agent->platform(); // Platform info (Windows, Linux, Mac, etc.) +</code> + + +<h1>Function Reference</h1> + + +<h2>$this->agent->is_browser()</h2> +<p>Returns TRUE/FALSE (boolean) if the user agent is a known web browser.</p> + +<h2>$this->agent->is_mobile()</h2> +<p>Returns TRUE/FALSE (boolean) if the user agent is a known mobile device.</p> + +<h2>$this->agent->is_robot()</h2> +<p>Returns TRUE/FALSE (boolean) if the user agent is a known robot.</p> + +<p class="important"><strong>Note:</strong> The user agent library only contains the most common robot +definitions. It is not a complete list of bots. There are hundreds of them so searching for each one would not be +very efficient. If you find that some bots that commonly visit your site are missing from the list you can add them to your +<dfn>application/config/user_agents.php</dfn> file.</p> + +<h2>$this->agent->is_referral()</h2> +<p>Returns TRUE/FALSE (boolean) if the user agent was referred from another site.</p> + + +<h2>$this->agent->browser()</h2> +<p>Returns a string containing the name of the web browser viewing your site.</p> + +<h2>$this->agent->version()</h2> +<p>Returns a string containing the version number of the web browser viewing your site.</p> + +<h2>$this->agent->mobile()</h2> +<p>Returns a string containing the name of the mobile device viewing your site.</p> + +<h2>$this->agent->robot()</h2> +<p>Returns a string containing the name of the robot viewing your site.</p> + +<h2>$this->agent->platform()</h2> +<p>Returns a string containing the platform viewing your site (Linux, Windows, OS X, etc.).</p> + +<h2>$this->agent->referrer()</h2> +<p>The referrer, if the user agent was referred from another site. Typically you'll test for this as follows:</p> + +<code> if ($this->agent->is_referral())<br /> +{<br /> + echo $this->agent->referrer();<br /> +}</code> + + +<h2>$this->agent->agent_string()</h2> +<p>Returns a string containing the full user agent string. Typically it will be something like this:</p> + +<code>Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.0.4) Gecko/20060613 Camino/1.0.2</code> + + +<h2>$this->agent->accept_lang()</h2> +<p>Lets you determine if the user agent accepts a particular language. Example:</p> + +<code>if ($this->agent->accept_lang('en'))<br /> +{<br /> + echo 'You accept English!';<br /> +}</code> + +<p class="important"><strong>Note:</strong> This function is not typically very reliable +since some browsers do not provide language info, and even among those that do, it is not always accurate. </p> + + + +<h2>$this->agent->accept_charset()</h2> +<p>Lets you determine if the user agent accepts a particular character set. Example:</p> + +<code>if ($this->agent->accept_charset('utf-8'))<br /> +{<br /> + echo 'You browser supports UTF-8!';<br /> +}</code> + +<p class="important"><strong>Note:</strong> This function is not typically very reliable +since some browsers do not provide character-set info, and even among those that do, it is not always accurate. </p> + + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="uri.html">URI Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="xmlrpc.html">XML-RPC Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/validation.html b/user_guide/libraries/validation.html index 6037a24e8..394be1901 100644 --- a/user_guide/libraries/validation.html +++ b/user_guide/libraries/validation.html @@ -1,736 +1,736 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Form Validation : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Form Validation
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-<h1>Form Validation</h1>
-
-<p>Before explaining CodeIgniter's approach to data validation, let's describe the ideal scenario:</p>
-
-<ol>
-<li>A form is displayed.</li>
-<li>You fill it in and submit it.</li>
-<li>If you submitted something invalid, or perhaps missed a required item, the form is redisplayed containing your data along with an error message describing the problem.</li>
-<li>This process continues until you have submitted a valid form.</li>
-</ol>
-
-<p>On the receiving end, the script must:</p>
-
-<ol>
-<li>Check for required data.</li>
-<li>Verify that the data is of the correct type, and meets the correct criteria. (For example, if a username is submitted
-it must be validated to contain only permitted characters. It must be of a minimum length,
-and not exceed a maximum length. The username can't be someone else's existing username, or perhaps even a reserved word. Etc.)</li>
-<li>Sanitize the data for security.</li>
-<li>Pre-format the data if needed (Does the data need to be trimmed? HTML encoded? Etc.)</li>
-<li>Prep the data for insertion in the database.</li>
-</ol>
-
-
-<p>Although there is nothing complex about the above process, it usually requires a significant
-amount of code, and to display error messages, various control structures are usually placed within the form HTML.
-Form validation, while simple to create, is generally very messy and tedious to implement.</p>
-
-<dfn>CodeIgniter provides a comprehensive validation framework that truly minimizes the amount of code you'll write.
-It also removes all control structures from your form HTML, permitting it to be clean and free of code.</dfn>
-
-<h2>Overview</h2>
-
-<p>In order to implement CodeIgniter's form validation you'll need three things:</p>
-
-<ol>
-<li>A <a href="../general/views.html">View</a> file containing the form.</li>
-<li>A View file containing a "success" message to be displayed upon successful submission.</li>
-<li>A <a href="../general/controllers.html">controller</a> function to receive and process the submitted data.</li>
-</ol>
-
-<p>Let's create those three things, using a member sign-up form as the example.</p>
-
-<h2>The Form</h2>
-
-<p>Using a text editor, create a form called <dfn>myform.php</dfn>. In it, place this code and save it to your <samp>applications/views/</samp>
-folder:</p>
-
-
-<textarea class="textarea" style="width:100%" cols="50" rows="30"><html>
-<head>
-<title>My Form</title>
-</head>
-<body>
-
-<?php echo $this->validation->error_string; ?>
-
-<?php echo form_open('form'); ?>
-
-<h5>Username</h5>
-<input type="text" name="username" value="" size="50" />
-
-<h5>Password</h5>
-<input type="text" name="password" value="" size="50" />
-
-<h5>Password Confirm</h5>
-<input type="text" name="passconf" value="" size="50" />
-
-<h5>Email Address</h5>
-<input type="text" name="email" value="" size="50" />
-
-<div><input type="submit" value="Submit" /></div>
-
-</form>
-
-</body>
-</html>
-</textarea>
-
-
-<h2>The Success Page</h2>
-
-
-<p>Using a text editor, create a form called <dfn>formsuccess.php</dfn>. In it, place this code and save it to your <samp>applications/views/</samp>
-folder:</p>
-
-
-<textarea class="textarea" style="width:100%" cols="50" rows="14">
-<html>
-<head>
-<title>My Form</title>
-</head>
-<body>
-
-<h3>Your form was successfully submitted!</h3>
-
-<p><?php echo anchor('form', 'Try it again!'); ?></p>
-
-</body>
-</html>
-</textarea>
-
-
-<h2>The Controller</h2>
-
-<p>Using a text editor, create a controller called <dfn>form.php</dfn>. In it, place this code and save it to your <samp>applications/controllers/</samp>
-folder:</p>
-
-
-<textarea class="textarea" style="width:100%" cols="50" rows="21"><?php
-
-class Form extends Controller {
-
- function index()
- {
- $this->load->helper(array('form', 'url'));
-
- $this->load->library('validation');
-
- if ($this->validation->run() == FALSE)
- {
- $this->load->view('myform');
- }
- else
- {
- $this->load->view('formsuccess');
- }
- }
-}
-?></textarea>
-
-
-<h2>Try it!</h2>
-
-<p>To try your form, visit your site using a URL similar to this one:</p>
-
-<code>example.com/index.php/<var>form</var>/</code>
-
-<p><strong>If you submit the form you should simply see the form reload. That's because you haven't set up any validation
-rules yet, which we'll get to in a moment.</strong></p>
-
-
-<h2>Explanation</h2>
-
-<p>You'll notice several things about the above pages:</p>
-
-<p>The <dfn>form</dfn> (myform.php) is a standard web form with a couple exceptions:</p>
-
-<ol>
-<li>It uses a <dfn>form helper</dfn> to create the form opening.
-Technically, this isn't necessary. You could create the form using standard HTML. However, the benefit of using the helper
-is that it generates the action URL for you, based on the URL in your config file. This makes your application more portable
-and flexible in the event your URLs change.</li>
-
-<li>At the top of the form you'll notice the following variable:
-<code><?php echo $this->validation->error_string; ?></code>
-
-<p>This variable will display any error messages sent back by the validator. If there are no messages it returns nothing.</p>
-</li>
-</ol>
-
-<p>The <dfn>controller</dfn> (form.php) has one function: <dfn>index()</dfn>. This function initializes the validation class and
-loads the <var>form helper</var> and <var>URL helper</var> used by your view files. It also <samp>runs</samp>
-the validation routine. Based on
-whether the validation was successful it either presents the form or the success page.</p>
-
-<p><strong>Since you haven't told the validation class to validate anything yet, it returns "false" (boolean false) by default. The <samp>run()</samp>
-function only returns "true" if it has successfully applied your rules without any of them failing.</strong></p>
-
-
-<h2>Setting Validation Rules</h2>
-
-<p>CodeIgniter lets you set as many validation rules as you need for a given field, cascading them in order, and it even lets you prep and pre-process the field data
-at the same time. Let's see it in action, we'll explain it afterwards.</p>
-
-<p>In your <dfn>controller</dfn> (form.php), add this code just below the validation initialization function:</p>
-
-<code>$rules['username'] = "required";<br />
-$rules['password'] = "required";<br />
-$rules['passconf'] = "required";<br />
-$rules['email'] = "required";<br />
-<br />
-$this->validation->set_rules($rules);</code>
-
-<p>Your controller should now look like this:</p>
-
-<textarea class="textarea" style="width:100%" cols="50" rows="28"><?php
-
-class Form extends Controller {
-
- function index()
- {
- $this->load->helper(array('form', 'url'));
-
- $this->load->library('validation');
-
- $rules['username'] = "required";
- $rules['password'] = "required";
- $rules['passconf'] = "required";
- $rules['email'] = "required";
-
- $this->validation->set_rules($rules);
-
- if ($this->validation->run() == FALSE)
- {
- $this->load->view('myform');
- }
- else
- {
- $this->load->view('formsuccess');
- }
- }
-}
-?></textarea>
-
-<p><dfn>Now submit the form with the fields blank and you should see the error message.
-If you submit the form with all the fields populated you'll see your success page.</dfn></p>
-
-<p class="important"><strong>Note:</strong> The form fields are not yet being re-populated with the data when
-there is an error. We'll get to that shortly, once we're through explaining the validation rules.</p>
-
-
-<h2>Changing the Error Delimiters</h2>
-
-<p>By default, the system adds a paragraph tag (<p>) around each error message shown. You can easily change these delimiters with
-this code, placed in your controller:</p>
-
-<code>$this->validation->set_error_delimiters('<kbd><div class="error"></kbd>', '<kbd></div></kbd>');</code>
-
-<p>In this example, we've switched to using div tags.</p>
-
-<h2>Cascading Rules</h2>
-
-<p>CodeIgniter lets you pipe multiple rules together. Let's try it. Change your rules array like this:</p>
-
-
-<code>$rules['username'] = "required|min_length[5]|max_length[12]";<br />
-$rules['password'] = "required|matches[passconf]";<br />
-$rules['passconf'] = "required";<br />
-$rules['email'] = "required|valid_email";</code>
-
-<p>The above code requires that:</p>
-
-<ol>
-<li>The username field be no shorter than 5 characters and no longer than 12.</li>
-<li>The password field must match the password confirmation field.</li>
-<li>The email field must contain a valid email address.</li>
-</ol>
-
-<p>Give it a try!</p>
-
-<p class="important"><strong>Note:</strong> There are numerous rules available which you can read about in the validation reference.</p>
-
-
-<h2>Prepping Data</h2>
-
-<p>In addition to the validation functions like the ones we used above, you can also prep your data in various ways.
-For example, you can set up rules like this:</p>
-
-<code>$rules['username'] = "<kbd>trim</kbd>|required|min_length[5]|max_length[12]|<kbd>xss_clean</kbd>";<br />
-$rules['password'] = "<kbd>trim</kbd>|required|matches[passconf]|<kbd>md5</kbd>";<br />
-$rules['passconf'] = "<kbd>trim</kbd>|required";<br />
-$rules['email'] = "<kbd>trim</kbd>|required|valid_email";</code>
-
-<p>In the above example, we are "trimming" the fields, converting the password to MD5, and running the username through
-the "xss_clean" function, which removes malicious data.</p>
-
-<p class="important"><strong>Any native PHP function that accepts one parameter can be used as a rule, like <dfn>htmlspecialchars</dfn>,
-<dfn>trim</dfn>, <dfn>MD5</dfn>, etc.</strong></p>
-
-<p><strong>Note:</strong> You will generally want to use the prepping functions <strong>after</strong>
-the validation rules so if there is an error, the original data will be shown in the form.</p>
-
-<h2>Callbacks: Your own Validation Functions</h2>
-
-<p>The validation system supports callbacks to your own validation functions. This permits you to extend the validation class
-to meet your needs. For example, if you need to run a database query to see if the user is choosing a unique username, you can
-create a callback function that does that. Let's create a simple example.</p>
-
-<p>In your controller, change the "username" rule to this:</p>
-
-<code>$rules['username'] = "callback_username_check"; </code>
-
-<p>Then add a new function called <dfn>username_check</dfn> to your controller. Here's how your controller should look:</p>
-
-
-<textarea class="textarea" style="width:100%" cols="50" rows="44"><?php
-
-class Form extends Controller {
-
- function index()
- {
- $this->load->helper(array('form', 'url'));
-
- $this->load->library('validation');
-
- $rules['username'] = "callback_username_check";
- $rules['password'] = "required";
- $rules['passconf'] = "required";
- $rules['email'] = "required";
-
- $this->validation->set_rules($rules);
-
- if ($this->validation->run() == FALSE)
- {
- $this->load->view('myform');
- }
- else
- {
- $this->load->view('formsuccess');
- }
- }
-
- function username_check($str)
- {
- if ($str == 'test')
- {
- $this->validation->set_message('username_check', 'The %s field can not be the word "test"');
- return FALSE;
- }
- else
- {
- return TRUE;
- }
- }
-
-}
-?></textarea>
-
-<p>Reload your form and submit it with the word "test" as the username. You can see that the form field data was passed to your
-callback function for you to process.</p>
-
-<p><strong>To invoke a callback just put the function name in a rule, with "callback_" as the rule prefix.</strong></p>
-
-<p>The error message was set using the <dfn>$this->validation->set_message</dfn> function.
-Just remember that the message key (the first parameter) must match your function name.</p>
-
-<p class="important"><strong>Note:</strong> You can apply your own custom error messages to any rule, just by setting the
-message similarly. For example, to change the message for the "required" rule you will do this:</p>
-
-<code>$this->validation->set_message('required', 'Your custom message here');</code>
-
-<h2>Re-populating the form</h2>
-
-<p>Thus far we have only been dealing with errors. It's time to repopulate the form field with the submitted data.
-This is done similarly to your rules. Add the following code to your controller, just below your rules:</p>
-
-<code>$fields['username'] = 'Username';<br />
-$fields['password'] = 'Password';<br />
-$fields['passconf'] = 'Password Confirmation';<br />
-$fields['email'] = 'Email Address';<br />
-<br />
-$this->validation->set_fields($fields);</code>
-
-<p>The array keys are the actual names of the form fields, the value represents the full name that you want shown in the
-error message.</p>
-
-<p>The index function of your controller should now look like this:</p>
-
-
-<textarea class="textarea" style="width:100%" cols="50" rows="30">function index()
-{
- $this->load->helper(array('form', 'url'));
-
- $this->load->library('validation');
-
- $rules['username'] = "required";
- $rules['password'] = "required";
- $rules['passconf'] = "required";
- $rules['email'] = "required";
-
- $this->validation->set_rules($rules);
-
- $fields['username'] = 'Username';
- $fields['password'] = 'Password';
- $fields['passconf'] = 'Password Confirmation';
- $fields['email'] = 'Email Address';
-
- $this->validation->set_fields($fields);
-
- if ($this->validation->run() == FALSE)
- {
- $this->load->view('myform');
- }
- else
- {
- $this->load->view('formsuccess');
- }
-}</textarea>
-
-
-<p>Now open your <dfn>myform.php</dfn> view file and update the value in each field so that it has an attribute corresponding to its name:</p>
-
-
-<textarea class="textarea" style="width:100%" cols="50" rows="30">
-<html>
-<head>
-<title>My Form</title>
-</head>
-<body>
-
-<?php echo $this->validation->error_string; ?>
-
-<?php echo form_open('form'); ?>
-
-<h5>Username</h5>
-<input type="text" name="username" value="<?php echo $this->validation->username;?>" size="50" />
-
-<h5>Password</h5>
-<input type="text" name="password" value="<?php echo $this->validation->password;?>" size="50" />
-
-<h5>Password Confirm</h5>
-<input type="text" name="passconf" value="<?php echo $this->validation->passconf;?>" size="50" />
-
-<h5>Email Address</h5>
-<input type="text" name="email" value="<?php echo $this->validation->email;?>" size="50" />
-
-<div><input type="submit" value="Submit" /></div>
-
-</form>
-
-</body>
-</html>
-</textarea>
-
-
-<p>Now reload your page and submit the form so that it triggers an error. Your form fields should be populated
-and the error messages will contain a more relevant field name.</p>
-
-
-
-<h2>Showing Errors Individually</h2>
-
-<p>If you prefer to show an error message next to each form field, rather than as a list, you can change your form so that it looks like this:</p>
-
-
-<textarea class="textarea" style="width:100%" cols="50" rows="20">
-<h5>Username</h5>
-<?php echo $this->validation->username_error; ?>
-<input type="text" name="username" value="<?php echo $this->validation->username;?>" size="50" />
-
-<h5>Password</h5>
-<?php echo $this->validation->password_error; ?>
-<input type="text" name="password" value="<?php echo $this->validation->password;?>" size="50" />
-
-<h5>Password Confirm</h5>
-<?php echo $this->validation->passconf_error; ?>
-<input type="text" name="passconf" value="<?php echo $this->validation->passconf;?>" size="50" />
-
-<h5>Email Address</h5>
-<?php echo $this->validation->email_error; ?>
-<input type="text" name="email" value="<?php echo $this->validation->email;?>" size="50" /></textarea>
-
-<p>If there are no errors, nothing will be shown. If there is an error, the message will appear, wrapped in the delimiters you
-have set (<p> tags by default).</p>
-
-<p class="important"><strong>Note: </strong>To display errors this way you must remember to set your fields using the <kbd>$this->validation->set_fields</kbd>
-function described earlier. The errors will be turned into variables that have "_error" after your field name.
-For example, your "username" error will be available at:<br /><dfn>$this->validation->username_error</dfn>.</p>
-
-
-<h2>Rule Reference</h2>
-
-<p>The following is a list of all the native rules that are available to use:</p>
-
-
-
-<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
-<tr>
-<th>Rule</th>
-<th>Parameter</th>
-<th>Description</th>
-<th>Example</th>
-</tr><tr>
-
-<td class="td"><strong>required</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the form element is empty.</td>
-<td class="td"> </td>
-</tr><tr>
-
-<td class="td"><strong>matches</strong></td>
-<td class="td">Yes</td>
-<td class="td">Returns FALSE if the form element does not match the one in the parameter.</td>
-<td class="td">matches[form_item]</td>
-</tr><tr>
-
-<td class="td"><strong>min_length</strong></td>
-<td class="td">Yes</td>
-<td class="td">Returns FALSE if the form element is shorter then the parameter value.</td>
-<td class="td">min_length[6]</td>
-</tr><tr>
-
-<td class="td"><strong>max_length</strong></td>
-<td class="td">Yes</td>
-<td class="td">Returns FALSE if the form element is longer then the parameter value.</td>
-<td class="td">max_length[12]</td>
-</tr><tr>
-
-<td class="td"><strong>exact_length</strong></td>
-<td class="td">Yes</td>
-<td class="td">Returns FALSE if the form element is not exactly the parameter value.</td>
-<td class="td">exact_length[8]</td>
-</tr><tr>
-
-<td class="td"><strong>alpha</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the form element contains anything other than alphabetical characters.</td>
-<td class="td"> </td>
-</tr><tr>
-
-<td class="td"><strong>alpha_numeric</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the form element contains anything other than alpha-numeric characters.</td>
-<td class="td"> </td>
-</tr><tr>
-
-<td class="td"><strong>alpha_dash</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the form element contains anything other than alpha-numeric characters, underscores or dashes.</td>
-<td class="td"> </td>
-</tr>
-<tr>
- <td class="td"><strong>numeric</strong></td>
- <td class="td">No</td>
- <td class="td">Returns FALSE if the form element contains anything other than numeric characters.</td>
- <td class="td"> </td>
-</tr>
-<tr>
-
-<td class="td"><strong>integer</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the form element contains anything other than an integer.</td>
-<td class="td"> </td>
-</tr><tr>
-
-<td class="td"><strong>valid_email</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the form element does not contain a valid email address.</td>
-<td class="td"> </td>
-</tr>
-<tr>
- <td class="td"><strong>valid_emails</strong></td>
- <td class="td">No</td>
- <td class="td">Returns FALSE if any value provided in a comma separated list is not a valid email.</td>
- <td class="td"> </td>
-</tr>
-<tr>
-<td class="td"><strong>valid_ip</strong></td>
-<td class="td">No</td>
-<td class="td">Returns FALSE if the supplied IP is not valid.</td>
-<td class="td"> </td>
-</tr>
-<tr>
- <td class="td"><strong>valid_base64</strong></td>
- <td class="td">No</td>
- <td class="td">Returns FALSE if the supplied string contains anything other than valid Base64 characters.</td>
- <td class="td"> </td>
-</tr>
-</table>
-
-<p><strong>Note:</strong> These rules can also be called as discrete functions. For example:</p>
-
-<code>$this->validation->required($string);</code>
-
-<p class="important"><strong>Note:</strong> You can also use any native PHP functions that permit one parameter.</p>
-
-
-
-<h2>Prepping Reference</h2>
-
-<p>The following is a list of all the prepping functions that are available to use:</p>
-
-
-
-<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
-<tr>
-<th>Name</th>
-<th>Parameter</th>
-<th>Description</th>
-</tr><tr>
-
-<td class="td"><strong>xss_clean</strong></td>
-<td class="td">No</td>
-<td class="td">Runs the data through the XSS filtering function, described in the <a href="input.html">Input Class</a> page.</td>
-</tr><tr>
-
-<td class="td"><strong>prep_for_form</strong></td>
-<td class="td">No</td>
-<td class="td">Converts special characters so that HTML data can be shown in a form field without breaking it.</td>
-</tr><tr>
-
-<td class="td"><strong>prep_url</strong></td>
-<td class="td">No</td>
-<td class="td">Adds "http://" to URLs if missing.</td>
-</tr><tr>
-
-<td class="td"><strong>strip_image_tags</strong></td>
-<td class="td">No</td>
-<td class="td">Strips the HTML from image tags leaving the raw URL.</td>
-</tr><tr>
-
-<td class="td"><strong>encode_php_tags</strong></td>
-<td class="td">No</td>
-<td class="td">Converts PHP tags to entities.</td>
-</tr>
-
-</table>
-
-<p class="important"><strong>Note:</strong> You can also use any native PHP functions that permit one parameter,
-like <kbd>trim</kbd>, <kbd>htmlspecialchars</kbd>, <kbd>urldecode</kbd>, etc.</p>
-
-
-<h2>Setting Custom Error Messages</h2>
-
-<p>All of the native error messages are located in the following language file: <dfn>language/english/validation_lang.php</dfn></p>
-
-<p>To set your own custom message you can either edit that file, or use the following function:</p>
-
-<code>$this->validation->set_message('<var>rule</var>', '<var>Error Message</var>');</code>
-
-<p>Where <var>rule</var> corresponds to the name of a particular rule, and <var>Error Message</var> is the text you would like displayed.</p>
-
-
-<h2>Dealing with Select Menus, Radio Buttons, and Checkboxes</h2>
-
-<p>If you use select menus, radio buttons or checkboxes, you will want the state of
-these items to be retained in the event of an error. The Validation class has three functions that help you do this:</p>
-
-<h2>set_select()</h2>
-
-<p>Permits you to display the menu item that was selected. The first parameter
-must contain the name of the select menu, the second parameter must contain the value of
-each item. Example:</p>
-
-<code>
-<select name="myselect"><br />
-<option value="one" <dfn><?php echo $this->validation->set_select('myselect', 'one'); ?></dfn> >One</option><br />
-<option value="two" <dfn><?php echo $this->validation->set_select('myselect', 'two'); ?></dfn> >Two</option><br />
-<option value="three" <dfn><?php echo $this->validation->set_select('myselect', 'three'); ?></dfn> >Three</option><br />
-</select>
-</code>
-
-
-<h2>set_checkbox()</h2>
-
-<p>Permits you to display a checkbox in the state it was submitted. The first parameter
-must contain the name of the checkbox, the second parameter must contain its value. Example:</p>
-
-<code><input type="checkbox" name="mycheck" value="1" <dfn><?php echo $this->validation->set_checkbox('mycheck', '1'); ?></dfn> /></code>
-
-
-<h2>set_radio()</h2>
-
-<p>Permits you to display radio buttons in the state they were submitted. The first parameter
-must contain the name of the radio button, the second parameter must contain its value. Example:</p>
-
-<code><input type="radio" name="myradio" value="1" <dfn><?php echo $this->validation->set_radio('myradio', '1'); ?></dfn> /></code>
-
-
-
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="user_agent.html">User Agent Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="xmlrpc.html">XML-RPC Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Form Validation : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Form Validation +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + +<h1>Form Validation</h1> + +<p>Before explaining CodeIgniter's approach to data validation, let's describe the ideal scenario:</p> + +<ol> +<li>A form is displayed.</li> +<li>You fill it in and submit it.</li> +<li>If you submitted something invalid, or perhaps missed a required item, the form is redisplayed containing your data along with an error message describing the problem.</li> +<li>This process continues until you have submitted a valid form.</li> +</ol> + +<p>On the receiving end, the script must:</p> + +<ol> +<li>Check for required data.</li> +<li>Verify that the data is of the correct type, and meets the correct criteria. (For example, if a username is submitted +it must be validated to contain only permitted characters. It must be of a minimum length, +and not exceed a maximum length. The username can't be someone else's existing username, or perhaps even a reserved word. Etc.)</li> +<li>Sanitize the data for security.</li> +<li>Pre-format the data if needed (Does the data need to be trimmed? HTML encoded? Etc.)</li> +<li>Prep the data for insertion in the database.</li> +</ol> + + +<p>Although there is nothing complex about the above process, it usually requires a significant +amount of code, and to display error messages, various control structures are usually placed within the form HTML. +Form validation, while simple to create, is generally very messy and tedious to implement.</p> + +<dfn>CodeIgniter provides a comprehensive validation framework that truly minimizes the amount of code you'll write. +It also removes all control structures from your form HTML, permitting it to be clean and free of code.</dfn> + +<h2>Overview</h2> + +<p>In order to implement CodeIgniter's form validation you'll need three things:</p> + +<ol> +<li>A <a href="../general/views.html">View</a> file containing the form.</li> +<li>A View file containing a "success" message to be displayed upon successful submission.</li> +<li>A <a href="../general/controllers.html">controller</a> function to receive and process the submitted data.</li> +</ol> + +<p>Let's create those three things, using a member sign-up form as the example.</p> + +<h2>The Form</h2> + +<p>Using a text editor, create a form called <dfn>myform.php</dfn>. In it, place this code and save it to your <samp>applications/views/</samp> +folder:</p> + + +<textarea class="textarea" style="width:100%" cols="50" rows="30"><html> +<head> +<title>My Form</title> +</head> +<body> + +<?php echo $this->validation->error_string; ?> + +<?php echo form_open('form'); ?> + +<h5>Username</h5> +<input type="text" name="username" value="" size="50" /> + +<h5>Password</h5> +<input type="text" name="password" value="" size="50" /> + +<h5>Password Confirm</h5> +<input type="text" name="passconf" value="" size="50" /> + +<h5>Email Address</h5> +<input type="text" name="email" value="" size="50" /> + +<div><input type="submit" value="Submit" /></div> + +</form> + +</body> +</html> +</textarea> + + +<h2>The Success Page</h2> + + +<p>Using a text editor, create a form called <dfn>formsuccess.php</dfn>. In it, place this code and save it to your <samp>applications/views/</samp> +folder:</p> + + +<textarea class="textarea" style="width:100%" cols="50" rows="14"> +<html> +<head> +<title>My Form</title> +</head> +<body> + +<h3>Your form was successfully submitted!</h3> + +<p><?php echo anchor('form', 'Try it again!'); ?></p> + +</body> +</html> +</textarea> + + +<h2>The Controller</h2> + +<p>Using a text editor, create a controller called <dfn>form.php</dfn>. In it, place this code and save it to your <samp>applications/controllers/</samp> +folder:</p> + + +<textarea class="textarea" style="width:100%" cols="50" rows="21"><?php + +class Form extends Controller { + + function index() + { + $this->load->helper(array('form', 'url')); + + $this->load->library('validation'); + + if ($this->validation->run() == FALSE) + { + $this->load->view('myform'); + } + else + { + $this->load->view('formsuccess'); + } + } +} +?></textarea> + + +<h2>Try it!</h2> + +<p>To try your form, visit your site using a URL similar to this one:</p> + +<code>example.com/index.php/<var>form</var>/</code> + +<p><strong>If you submit the form you should simply see the form reload. That's because you haven't set up any validation +rules yet, which we'll get to in a moment.</strong></p> + + +<h2>Explanation</h2> + +<p>You'll notice several things about the above pages:</p> + +<p>The <dfn>form</dfn> (myform.php) is a standard web form with a couple exceptions:</p> + +<ol> +<li>It uses a <dfn>form helper</dfn> to create the form opening. +Technically, this isn't necessary. You could create the form using standard HTML. However, the benefit of using the helper +is that it generates the action URL for you, based on the URL in your config file. This makes your application more portable +and flexible in the event your URLs change.</li> + +<li>At the top of the form you'll notice the following variable: +<code><?php echo $this->validation->error_string; ?></code> + +<p>This variable will display any error messages sent back by the validator. If there are no messages it returns nothing.</p> +</li> +</ol> + +<p>The <dfn>controller</dfn> (form.php) has one function: <dfn>index()</dfn>. This function initializes the validation class and +loads the <var>form helper</var> and <var>URL helper</var> used by your view files. It also <samp>runs</samp> +the validation routine. Based on +whether the validation was successful it either presents the form or the success page.</p> + +<p><strong>Since you haven't told the validation class to validate anything yet, it returns "false" (boolean false) by default. The <samp>run()</samp> +function only returns "true" if it has successfully applied your rules without any of them failing.</strong></p> + + +<h2>Setting Validation Rules</h2> + +<p>CodeIgniter lets you set as many validation rules as you need for a given field, cascading them in order, and it even lets you prep and pre-process the field data +at the same time. Let's see it in action, we'll explain it afterwards.</p> + +<p>In your <dfn>controller</dfn> (form.php), add this code just below the validation initialization function:</p> + +<code>$rules['username'] = "required";<br /> +$rules['password'] = "required";<br /> +$rules['passconf'] = "required";<br /> +$rules['email'] = "required";<br /> +<br /> +$this->validation->set_rules($rules);</code> + +<p>Your controller should now look like this:</p> + +<textarea class="textarea" style="width:100%" cols="50" rows="28"><?php + +class Form extends Controller { + + function index() + { + $this->load->helper(array('form', 'url')); + + $this->load->library('validation'); + + $rules['username'] = "required"; + $rules['password'] = "required"; + $rules['passconf'] = "required"; + $rules['email'] = "required"; + + $this->validation->set_rules($rules); + + if ($this->validation->run() == FALSE) + { + $this->load->view('myform'); + } + else + { + $this->load->view('formsuccess'); + } + } +} +?></textarea> + +<p><dfn>Now submit the form with the fields blank and you should see the error message. +If you submit the form with all the fields populated you'll see your success page.</dfn></p> + +<p class="important"><strong>Note:</strong> The form fields are not yet being re-populated with the data when +there is an error. We'll get to that shortly, once we're through explaining the validation rules.</p> + + +<h2>Changing the Error Delimiters</h2> + +<p>By default, the system adds a paragraph tag (<p>) around each error message shown. You can easily change these delimiters with +this code, placed in your controller:</p> + +<code>$this->validation->set_error_delimiters('<kbd><div class="error"></kbd>', '<kbd></div></kbd>');</code> + +<p>In this example, we've switched to using div tags.</p> + +<h2>Cascading Rules</h2> + +<p>CodeIgniter lets you pipe multiple rules together. Let's try it. Change your rules array like this:</p> + + +<code>$rules['username'] = "required|min_length[5]|max_length[12]";<br /> +$rules['password'] = "required|matches[passconf]";<br /> +$rules['passconf'] = "required";<br /> +$rules['email'] = "required|valid_email";</code> + +<p>The above code requires that:</p> + +<ol> +<li>The username field be no shorter than 5 characters and no longer than 12.</li> +<li>The password field must match the password confirmation field.</li> +<li>The email field must contain a valid email address.</li> +</ol> + +<p>Give it a try!</p> + +<p class="important"><strong>Note:</strong> There are numerous rules available which you can read about in the validation reference.</p> + + +<h2>Prepping Data</h2> + +<p>In addition to the validation functions like the ones we used above, you can also prep your data in various ways. +For example, you can set up rules like this:</p> + +<code>$rules['username'] = "<kbd>trim</kbd>|required|min_length[5]|max_length[12]|<kbd>xss_clean</kbd>";<br /> +$rules['password'] = "<kbd>trim</kbd>|required|matches[passconf]|<kbd>md5</kbd>";<br /> +$rules['passconf'] = "<kbd>trim</kbd>|required";<br /> +$rules['email'] = "<kbd>trim</kbd>|required|valid_email";</code> + +<p>In the above example, we are "trimming" the fields, converting the password to MD5, and running the username through +the "xss_clean" function, which removes malicious data.</p> + +<p class="important"><strong>Any native PHP function that accepts one parameter can be used as a rule, like <dfn>htmlspecialchars</dfn>, +<dfn>trim</dfn>, <dfn>MD5</dfn>, etc.</strong></p> + +<p><strong>Note:</strong> You will generally want to use the prepping functions <strong>after</strong> +the validation rules so if there is an error, the original data will be shown in the form.</p> + +<h2>Callbacks: Your own Validation Functions</h2> + +<p>The validation system supports callbacks to your own validation functions. This permits you to extend the validation class +to meet your needs. For example, if you need to run a database query to see if the user is choosing a unique username, you can +create a callback function that does that. Let's create a simple example.</p> + +<p>In your controller, change the "username" rule to this:</p> + +<code>$rules['username'] = "callback_username_check"; </code> + +<p>Then add a new function called <dfn>username_check</dfn> to your controller. Here's how your controller should look:</p> + + +<textarea class="textarea" style="width:100%" cols="50" rows="44"><?php + +class Form extends Controller { + + function index() + { + $this->load->helper(array('form', 'url')); + + $this->load->library('validation'); + + $rules['username'] = "callback_username_check"; + $rules['password'] = "required"; + $rules['passconf'] = "required"; + $rules['email'] = "required"; + + $this->validation->set_rules($rules); + + if ($this->validation->run() == FALSE) + { + $this->load->view('myform'); + } + else + { + $this->load->view('formsuccess'); + } + } + + function username_check($str) + { + if ($str == 'test') + { + $this->validation->set_message('username_check', 'The %s field can not be the word "test"'); + return FALSE; + } + else + { + return TRUE; + } + } + +} +?></textarea> + +<p>Reload your form and submit it with the word "test" as the username. You can see that the form field data was passed to your +callback function for you to process.</p> + +<p><strong>To invoke a callback just put the function name in a rule, with "callback_" as the rule prefix.</strong></p> + +<p>The error message was set using the <dfn>$this->validation->set_message</dfn> function. +Just remember that the message key (the first parameter) must match your function name.</p> + +<p class="important"><strong>Note:</strong> You can apply your own custom error messages to any rule, just by setting the +message similarly. For example, to change the message for the "required" rule you will do this:</p> + +<code>$this->validation->set_message('required', 'Your custom message here');</code> + +<h2>Re-populating the form</h2> + +<p>Thus far we have only been dealing with errors. It's time to repopulate the form field with the submitted data. +This is done similarly to your rules. Add the following code to your controller, just below your rules:</p> + +<code>$fields['username'] = 'Username';<br /> +$fields['password'] = 'Password';<br /> +$fields['passconf'] = 'Password Confirmation';<br /> +$fields['email'] = 'Email Address';<br /> +<br /> +$this->validation->set_fields($fields);</code> + +<p>The array keys are the actual names of the form fields, the value represents the full name that you want shown in the +error message.</p> + +<p>The index function of your controller should now look like this:</p> + + +<textarea class="textarea" style="width:100%" cols="50" rows="30">function index() +{ + $this->load->helper(array('form', 'url')); + + $this->load->library('validation'); + + $rules['username'] = "required"; + $rules['password'] = "required"; + $rules['passconf'] = "required"; + $rules['email'] = "required"; + + $this->validation->set_rules($rules); + + $fields['username'] = 'Username'; + $fields['password'] = 'Password'; + $fields['passconf'] = 'Password Confirmation'; + $fields['email'] = 'Email Address'; + + $this->validation->set_fields($fields); + + if ($this->validation->run() == FALSE) + { + $this->load->view('myform'); + } + else + { + $this->load->view('formsuccess'); + } +}</textarea> + + +<p>Now open your <dfn>myform.php</dfn> view file and update the value in each field so that it has an attribute corresponding to its name:</p> + + +<textarea class="textarea" style="width:100%" cols="50" rows="30"> +<html> +<head> +<title>My Form</title> +</head> +<body> + +<?php echo $this->validation->error_string; ?> + +<?php echo form_open('form'); ?> + +<h5>Username</h5> +<input type="text" name="username" value="<?php echo $this->validation->username;?>" size="50" /> + +<h5>Password</h5> +<input type="text" name="password" value="<?php echo $this->validation->password;?>" size="50" /> + +<h5>Password Confirm</h5> +<input type="text" name="passconf" value="<?php echo $this->validation->passconf;?>" size="50" /> + +<h5>Email Address</h5> +<input type="text" name="email" value="<?php echo $this->validation->email;?>" size="50" /> + +<div><input type="submit" value="Submit" /></div> + +</form> + +</body> +</html> +</textarea> + + +<p>Now reload your page and submit the form so that it triggers an error. Your form fields should be populated +and the error messages will contain a more relevant field name.</p> + + + +<h2>Showing Errors Individually</h2> + +<p>If you prefer to show an error message next to each form field, rather than as a list, you can change your form so that it looks like this:</p> + + +<textarea class="textarea" style="width:100%" cols="50" rows="20"> +<h5>Username</h5> +<?php echo $this->validation->username_error; ?> +<input type="text" name="username" value="<?php echo $this->validation->username;?>" size="50" /> + +<h5>Password</h5> +<?php echo $this->validation->password_error; ?> +<input type="text" name="password" value="<?php echo $this->validation->password;?>" size="50" /> + +<h5>Password Confirm</h5> +<?php echo $this->validation->passconf_error; ?> +<input type="text" name="passconf" value="<?php echo $this->validation->passconf;?>" size="50" /> + +<h5>Email Address</h5> +<?php echo $this->validation->email_error; ?> +<input type="text" name="email" value="<?php echo $this->validation->email;?>" size="50" /></textarea> + +<p>If there are no errors, nothing will be shown. If there is an error, the message will appear, wrapped in the delimiters you +have set (<p> tags by default).</p> + +<p class="important"><strong>Note: </strong>To display errors this way you must remember to set your fields using the <kbd>$this->validation->set_fields</kbd> +function described earlier. The errors will be turned into variables that have "_error" after your field name. +For example, your "username" error will be available at:<br /><dfn>$this->validation->username_error</dfn>.</p> + + +<h2>Rule Reference</h2> + +<p>The following is a list of all the native rules that are available to use:</p> + + + +<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder"> +<tr> +<th>Rule</th> +<th>Parameter</th> +<th>Description</th> +<th>Example</th> +</tr><tr> + +<td class="td"><strong>required</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the form element is empty.</td> +<td class="td"> </td> +</tr><tr> + +<td class="td"><strong>matches</strong></td> +<td class="td">Yes</td> +<td class="td">Returns FALSE if the form element does not match the one in the parameter.</td> +<td class="td">matches[form_item]</td> +</tr><tr> + +<td class="td"><strong>min_length</strong></td> +<td class="td">Yes</td> +<td class="td">Returns FALSE if the form element is shorter then the parameter value.</td> +<td class="td">min_length[6]</td> +</tr><tr> + +<td class="td"><strong>max_length</strong></td> +<td class="td">Yes</td> +<td class="td">Returns FALSE if the form element is longer then the parameter value.</td> +<td class="td">max_length[12]</td> +</tr><tr> + +<td class="td"><strong>exact_length</strong></td> +<td class="td">Yes</td> +<td class="td">Returns FALSE if the form element is not exactly the parameter value.</td> +<td class="td">exact_length[8]</td> +</tr><tr> + +<td class="td"><strong>alpha</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the form element contains anything other than alphabetical characters.</td> +<td class="td"> </td> +</tr><tr> + +<td class="td"><strong>alpha_numeric</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the form element contains anything other than alpha-numeric characters.</td> +<td class="td"> </td> +</tr><tr> + +<td class="td"><strong>alpha_dash</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the form element contains anything other than alpha-numeric characters, underscores or dashes.</td> +<td class="td"> </td> +</tr> +<tr> + <td class="td"><strong>numeric</strong></td> + <td class="td">No</td> + <td class="td">Returns FALSE if the form element contains anything other than numeric characters.</td> + <td class="td"> </td> +</tr> +<tr> + +<td class="td"><strong>integer</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the form element contains anything other than an integer.</td> +<td class="td"> </td> +</tr><tr> + +<td class="td"><strong>valid_email</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the form element does not contain a valid email address.</td> +<td class="td"> </td> +</tr> +<tr> + <td class="td"><strong>valid_emails</strong></td> + <td class="td">No</td> + <td class="td">Returns FALSE if any value provided in a comma separated list is not a valid email.</td> + <td class="td"> </td> +</tr> +<tr> +<td class="td"><strong>valid_ip</strong></td> +<td class="td">No</td> +<td class="td">Returns FALSE if the supplied IP is not valid.</td> +<td class="td"> </td> +</tr> +<tr> + <td class="td"><strong>valid_base64</strong></td> + <td class="td">No</td> + <td class="td">Returns FALSE if the supplied string contains anything other than valid Base64 characters.</td> + <td class="td"> </td> +</tr> +</table> + +<p><strong>Note:</strong> These rules can also be called as discrete functions. For example:</p> + +<code>$this->validation->required($string);</code> + +<p class="important"><strong>Note:</strong> You can also use any native PHP functions that permit one parameter.</p> + + + +<h2>Prepping Reference</h2> + +<p>The following is a list of all the prepping functions that are available to use:</p> + + + +<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder"> +<tr> +<th>Name</th> +<th>Parameter</th> +<th>Description</th> +</tr><tr> + +<td class="td"><strong>xss_clean</strong></td> +<td class="td">No</td> +<td class="td">Runs the data through the XSS filtering function, described in the <a href="input.html">Input Class</a> page.</td> +</tr><tr> + +<td class="td"><strong>prep_for_form</strong></td> +<td class="td">No</td> +<td class="td">Converts special characters so that HTML data can be shown in a form field without breaking it.</td> +</tr><tr> + +<td class="td"><strong>prep_url</strong></td> +<td class="td">No</td> +<td class="td">Adds "http://" to URLs if missing.</td> +</tr><tr> + +<td class="td"><strong>strip_image_tags</strong></td> +<td class="td">No</td> +<td class="td">Strips the HTML from image tags leaving the raw URL.</td> +</tr><tr> + +<td class="td"><strong>encode_php_tags</strong></td> +<td class="td">No</td> +<td class="td">Converts PHP tags to entities.</td> +</tr> + +</table> + +<p class="important"><strong>Note:</strong> You can also use any native PHP functions that permit one parameter, +like <kbd>trim</kbd>, <kbd>htmlspecialchars</kbd>, <kbd>urldecode</kbd>, etc.</p> + + +<h2>Setting Custom Error Messages</h2> + +<p>All of the native error messages are located in the following language file: <dfn>language/english/validation_lang.php</dfn></p> + +<p>To set your own custom message you can either edit that file, or use the following function:</p> + +<code>$this->validation->set_message('<var>rule</var>', '<var>Error Message</var>');</code> + +<p>Where <var>rule</var> corresponds to the name of a particular rule, and <var>Error Message</var> is the text you would like displayed.</p> + + +<h2>Dealing with Select Menus, Radio Buttons, and Checkboxes</h2> + +<p>If you use select menus, radio buttons or checkboxes, you will want the state of +these items to be retained in the event of an error. The Validation class has three functions that help you do this:</p> + +<h2>set_select()</h2> + +<p>Permits you to display the menu item that was selected. The first parameter +must contain the name of the select menu, the second parameter must contain the value of +each item. Example:</p> + +<code> +<select name="myselect"><br /> +<option value="one" <dfn><?php echo $this->validation->set_select('myselect', 'one'); ?></dfn> >One</option><br /> +<option value="two" <dfn><?php echo $this->validation->set_select('myselect', 'two'); ?></dfn> >Two</option><br /> +<option value="three" <dfn><?php echo $this->validation->set_select('myselect', 'three'); ?></dfn> >Three</option><br /> +</select> +</code> + + +<h2>set_checkbox()</h2> + +<p>Permits you to display a checkbox in the state it was submitted. The first parameter +must contain the name of the checkbox, the second parameter must contain its value. Example:</p> + +<code><input type="checkbox" name="mycheck" value="1" <dfn><?php echo $this->validation->set_checkbox('mycheck', '1'); ?></dfn> /></code> + + +<h2>set_radio()</h2> + +<p>Permits you to display radio buttons in the state they were submitted. The first parameter +must contain the name of the radio button, the second parameter must contain its value. Example:</p> + +<code><input type="radio" name="myradio" value="1" <dfn><?php echo $this->validation->set_radio('myradio', '1'); ?></dfn> /></code> + + + + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="user_agent.html">User Agent Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="xmlrpc.html">XML-RPC Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/xmlrpc.html b/user_guide/libraries/xmlrpc.html index 9c1b7145f..e329e4a95 100644 --- a/user_guide/libraries/xmlrpc.html +++ b/user_guide/libraries/xmlrpc.html @@ -1,517 +1,517 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>XML-RPC and XML-RPC Server Classes : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-XML-RPC and XML-RPC Server Classes
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>XML-RPC and XML-RPC Server Classes</h1>
-
-
-<p>CodeIgniter's XML-RPC classes permit you to send requests to another server, or set up
-your own XML-RPC server to receive requests.</p>
-
-
-<h2>What is XML-RPC?</h2>
-
-<p>Quite simply it is a way for two computers to communicate over the internet using XML.
-One computer, which we will call the <dfn>client</dfn>, sends an XML-RPC <strong>request</strong> to
-another computer, which we will call the <dfn>server</dfn>. Once the server receives and processes the request it
-will send back a <strong>response</strong> to the client.</p>
-
-<p>For example, using the MetaWeblog API, an XML-RPC Client (usually a desktop publishing tool) will
-send a request to an XML-RPC Server running on your site. This request might be a new weblog entry
-being sent for publication, or it could be a request for an existing entry for editing.
-
-When the XML-RPC Server receives this request it will examine it to determine which class/method should be called to process the request.
-Once processed, the server will then send back a response message.</p>
-
-<p>For detailed specifications, you can visit the <a href="http://www.xmlrpc.com/">XML-RPC</a> site.</p>
-
-<h2>Initializing the Class</h2>
-
-<p>Like most other classes in CodeIgniter, the XML-RPC and XML-RPCS classes are initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
-
-<p>To load the XML-RPC class you will use:</p>
-<code>$this->load->library('xmlrpc');</code>
-<p>Once loaded, the xml-rpc library object will be available using: <dfn>$this->xmlrpc</dfn></p>
-
-<p>To load the XML-RPC Server class you will use:</p>
-<code>
-$this->load->library('xmlrpc');<br />
-$this->load->library('xmlrpcs');
-</code>
-<p>Once loaded, the xml-rpcs library object will be available using: <dfn>$this->xmlrpcs</dfn></p>
-
-<p class="important"><strong>Note:</strong> When using the XML-RPC Server class you must load BOTH the XML-RPC class and the XML-RPC Server class.</p>
-
-
-
-<h2>Sending XML-RPC Requests</h2>
-
-<p>To send a request to an XML-RPC server you must specify the following information:</p>
-
-<ul>
-<li>The URL of the server</li>
-<li>The method on the server you wish to call</li>
-<li>The <em>request</em> data (explained below).</li>
-</ul>
-
-<p>Here is a basic example that sends a simple Weblogs.com ping to the <a href="http://pingomatic.com/">Ping-o-Matic</a></p>
-
-
-<code>$this->load->library('xmlrpc');<br />
-<br />
-$this->xmlrpc->server('http://rpc.pingomatic.com/', 80);<br />
-$this->xmlrpc->method('weblogUpdates.ping');<br />
-
-<br />
-$request = array('My Photoblog', 'http://www.my-site.com/photoblog/');<br />
-$this->xmlrpc->request($request);<br />
-<br />
-if ( ! $this->xmlrpc->send_request())<br />
-{<br />
- echo $this->xmlrpc->display_error();<br />
-}</code>
-
-<h3>Explanation</h3>
-
-<p>The above code initializes the XML-RPC class, sets the server URL and method to be called (weblogUpdates.ping). The
-request (in this case, the title and URL of your site) is placed into an array for transportation, and
-compiled using the request() function.
-Lastly, the full request is sent. If the <dfn>send_request()</dfn> method returns false we will display the error message
-sent back from the XML-RPC Server.</p>
-
-<h2>Anatomy of a Request</h2>
-
-<p>An XML-RPC <dfn>request</dfn> is simply the data you are sending to the XML-RPC server. Each piece of data in a request
-is referred to as a <dfn>request parameter</dfn>. The above example has two parameters:
-The URL and title of your site. When the XML-RPC server receives your request, it will look for parameters it requires.</p>
-
-<p>Request parameters must be placed into an array for transportation, and each parameter can be one
-of seven data types (strings, numbers, dates, etc.). If your parameters are something other than strings
-you will have to include the data type in the request array.</p>
-
-<p>Here is an example of a simple array with three parameters:</p>
-
-<code>$request = array('John', 'Doe', 'www.some-site.com');<br />
-$this->xmlrpc->request($request);</code>
-
-<p>If you use data types other than strings, or if you have several different data types, you will place
-each parameter into its own array, with the data type in the second position:</p>
-
-<code>
-$request = array (<br />
- array('John', 'string'),<br />
- array('Doe', 'string'),<br />
- array(FALSE, 'boolean'),<br />
- array(12345, 'int')<br />
- );
-<br />
-$this->xmlrpc->request($request);</code>
-
-The <a href="#datatypes">Data Types</a> section below has a full list of data types.
-
-
-
-<h2>Creating an XML-RPC Server</h2>
-
-<p>An XML-RPC Server acts as a traffic cop of sorts, waiting for incoming requests and redirecting them to the
-appropriate functions for processing.</p>
-
-<p>To create your own XML-RPC server involves initializing the XML-RPC Server class in your controller where you expect the incoming
-request to appear, then setting up an array with mapping instructions so that incoming requests can be sent to the appropriate
-class and method for processing.</p>
-
-<p>Here is an example to illustrate:</p>
-
-<code>
-$this->load->library('xmlrpc');<br />
-$this->load->library('xmlrpcs');<br />
-<br />
-$config['functions']['<var>new_post</var>'] = array('function' => '<dfn>My_blog.new_entry</dfn>'),<br />
-$config['functions']['<var>update_post</var>'] = array('function' => '<dfn>My_blog.update_entry</dfn>');<br />
-$config['object'] = $this;<br />
-<br />
-$this->xmlrpcs->initialize($config);<br />
-$this->xmlrpcs->serve();</code>
-
-<p>The above example contains an array specifying two method requests that the Server allows.
-The allowed methods are on the left side of the array. When either of those are received, they will be mapped to the class and method on the right.</p>
-
-<p>The '<var>object</var>' key is a special key that you pass an instantiated class object with, which is necessary when the method you are mapping to is not
- part of the CodeIgniter super object.</p>
-
-<p>In other words, if an XML-RPC Client sends a request for the <var>new_post</var> method, your
-server will load the <dfn>My_blog</dfn> class and call the <dfn>new_entry</dfn> function.
-If the request is for the <var>update_post</var> method, your
-server will load the <dfn>My_blog</dfn> class and call the <dfn>update_entry</dfn> function.</p>
-
-<p>The function names in the above example are arbitrary. You'll decide what they should be called on your server,
-or if you are using standardized APIs, like the Blogger or MetaWeblog API, you'll use their function names.</p>
-
-<h2>Processing Server Requests</h2>
-
-<p>When the XML-RPC Server receives a request and loads the class/method for processing, it will pass
-an object to that method containing the data sent by the client.</p>
-
-<p>Using the above example, if the <var>new_post</var> method is requested, the server will expect a class
-to exist with this prototype:</p>
-
-<code>class <kbd>My_blog</kbd> extends Controller {<br />
-<br />
- function <kbd>new_post</kbd>(<var>$request</var>)<br />
- {<br />
- <br />
- }<br />
-}
-</code>
-
-<p>The <var>$request</var> variable is an object compiled by the Server, which contains the data sent by the XML-RPC Client.
-Using this object you will have access to the <em>request parameters</em> enabling you to process the request. When
-you are done you will send a <dfn>Response</dfn> back to the Client.</p>
-
-<p>Below is a real-world example, using the Blogger API. One of the methods in the Blogger API is <dfn>getUserInfo()</dfn>.
-Using this method, an XML-RPC Client can send the Server a username and password, in return the Server sends
-back information about that particular user (nickname, user ID, email address, etc.). Here is how the processing
-function might look:</p>
-
-
-<code>class <kbd>My_blog</kbd> extends Controller {<br />
-<br />
- function <kbd>getUserInfo</kbd>(<var>$request</var>)<br />
- {<br />
-
- $username = 'smitty';<br />
- $password = 'secretsmittypass';<br /><br />
-
- $this->load->library('xmlrpc');<br />
- <br />
- $parameters = $request->output_parameters();<br />
- <br />
- if ($parameters['1'] != $username AND $parameters['2'] != $password)<br />
- {<br />
- return $this->xmlrpc->send_error_message('100', 'Invalid Access');<br />
- }<br />
- <br />
- $response = array(array('nickname' => array('Smitty','string'),<br />
- 'userid' => array('99','string'),<br />
- 'url' => array('http://yoursite.com','string'),<br />
- 'email' => array('jsmith@yoursite.com','string'),<br />
- 'lastname' => array('Smith','string'),<br />
- 'firstname' => array('John','string')<br />
- ),<br />
- 'struct');<br />
-<br />
- return $this->xmlrpc->send_response($response);<br />
- }<br />
-}
-</code>
-
-<h3>Notes:</h3>
-<p>The <dfn>output_parameters()</dfn> function retrieves an indexed array corresponding to the request parameters sent by the client.
-In the above example, the output parameters will be the username and password.</p>
-
-<p>If the username and password sent by the client were not valid, and error message is returned using <dfn>send_error_message()</dfn>.</p>
-
-<p>If the operation was successful, the client will be sent back a response array containing the user's info.</p>
-
-
-<h2>Formatting a Response</h2>
-
-<p>Similar to <em>Requests</em>, <em>Responses</em> must be formatted as an array. However, unlike requests, a response is an array
-<strong>that contains a single item</strong>. This item can be an array with several additional arrays, but there
-can be only one primary array index. In other words, the basic prototype is this:</p>
-
-<code>$response = array('Response data', 'array');</code>
-
-<p>Responses, however, usually contain multiple pieces of information. In order to accomplish this we must put the response into its own
-array so that the primary array continues to contain a single piece of data. Here's an example showing how this might be accomplished:</p>
-
-<code>
-$response = array (<br />
- array(<br />
- 'first_name' => array('John', 'string'),<br />
- 'last_name' => array('Doe', 'string'),<br />
- 'member_id' => array(123435, 'int'),<br />
- 'todo_list' => array(array('clean house', 'call mom', 'water plants'), 'array'),<br />
- ),<br />
- 'struct'<br />
- );
-</code>
-
-<p class="important">Notice that the above array is formatted as a <dfn>struct</dfn>. This is the most common data type for responses.</p>
-
-<p>As with Requests, a response can be one of the seven data types listed in the <a href="#datatypes">Data Types</a> section.</p>
-
-
-<h2>Sending an Error Response</h2>
-
-<p>If you need to send the client an error response you will use the following:</p>
-
-<code>return $this->xmlrpc->send_error_message('123', 'Requested data not available');</code>
-
-<p>The first parameter is the error number while the second parameter is the error message.</p>
-
-
-
-
-
-
-<h2>Creating Your Own Client and Server</h2>
-
-<p>To help you understand everything we've covered thus far, let's create a couple controllers that act as
-XML-RPC Client and Server. You'll use the Client to send a request to the Server and receive a response.</p>
-
-<h3>The Client</h3>
-
-<p>Using a text editor, create a controller called <dfn>xmlrpc_client.php</dfn>.
-In it, place this code and save it to your <samp>applications/controllers/</samp> folder:</p>
-
-<textarea class="textarea" style="width:100%" cols="50" rows="32"><?php
-
-class Xmlrpc_client extends Controller {
-
- function index()
- {
- $this->load->helper('url');
- $server_url = site_url('xmlrpc_server');
-
- $this->load->library('xmlrpc');
-
- $this->xmlrpc->server($server_url, 80);
- $this->xmlrpc->method('Greetings');
-
- $request = array('How is it going?');
- $this->xmlrpc->request($request);
-
- if ( ! $this->xmlrpc->send_request())
- {
- echo $this->xmlrpc->display_error();
- }
- else
- {
- echo '<pre>';
- print_r($this->xmlrpc->display_response());
- echo '</pre>';
- }
- }
-}
-?></textarea>
-
-<p>Note: In the above code we are using a "url helper". You can find more information in the <a href="../general/helpers.html">Helpers Functions</a> page.</p>
-
-<h3>The Server</h3>
-
-<p>Using a text editor, create a controller called <dfn>xmlrpc_server.php</dfn>.
-In it, place this code and save it to your <samp>applications/controllers/</samp> folder:</p>
-
-<textarea class="textarea" style="width:100%" cols="50" rows="30"><?php
-
-class Xmlrpc_server extends Controller {
-
- function index()
- {
- $this->load->library('xmlrpc');
- $this->load->library('xmlrpcs');
-
- $config['functions']['Greetings'] = array('function' => 'Xmlrpc_server.process');
-
- $this->xmlrpcs->initialize($config);
- $this->xmlrpcs->serve();
- }
-
-
- function process($request)
- {
- $parameters = $request->output_parameters();
-
- $response = array(
- array(
- 'you_said' => $parameters['0'],
- 'i_respond' => 'Not bad at all.'),
- 'struct');
-
- return $this->xmlrpc->send_response($response);
- }
-}
-?></textarea>
-
-<h3>Try it!</h3>
-
-<p>Now visit the your site using a URL similar to this:</p>
-<code>example.com/index.php/<var>xmlrpc_client</var>/</code>
-
-<p>You should now see the message you sent to the server, and its response back to you.</p>
-
-<p>The client you created sends a message ("How's is going?") to the server, along with a request for the "Greetings" method.
-The Server receives the request and maps it to the "process" function, where a response is sent back.</p>
-
-<h2>Using Associative Arrays In a Request Parameter</h2>
-
-<p>If you wish to use an associative array in your method parameters you will need to use a struct datatype:</p>
-
-<code>$request = array(<br />
- array(<br />
- // Param 0<br />
- array(<br />
- 'name'=>'John'<br />
- ),<br />
- 'struct'<br />
- ),<br />
- array(<br />
- // Param 1<br />
- array(<br />
- 'size'=>'large',<br />
- 'shape'=>'round'<br />
- ),<br />
- 'struct'<br />
- )<br />
- );<br />
- $this->xmlrpc->request($request);</code>
-
-<p>You can retrieve the associative array when processing the request in the Server.</p>
-
-<code>$parameters = $request->output_parameters();<br />
- $name = $parameters['0']['name'];<br />
- $size = $parameters['1']['size'];<br />
- $size = $parameters['1']['shape']; </code>
-
-<h1>XML-RPC Function Reference</h1>
-
-<h2>$this->xmlrpc->server()</h2>
-<p>Sets the URL and port number of the server to which a request is to be sent:</p>
-<code>$this->xmlrpc->server('http://www.sometimes.com/pings.php', 80);</code>
-
-<h2>$this->xmlrpc->timeout()</h2>
-<p>Set a time out period (in seconds) after which the request will be canceled:</p>
-<code>$this->xmlrpc->timeout(6);</code>
-
-<h2>$this->xmlrpc->method()</h2>
-<p>Sets the method that will be requested from the XML-RPC server:</p>
-<code>$this->xmlrpc->method('<var>method</var>');</code>
-
-<p>Where <var>method</var> is the name of the method.</p>
-
-<h2>$this->xmlrpc->request()</h2>
-<p>Takes an array of data and builds request to be sent to XML-RPC server:</p>
-<code>$request = array(array('My Photoblog', 'string'), 'http://www.yoursite.com/photoblog/');<br />
-$this->xmlrpc->request($request);</code>
-
-<h2>$this->xmlrpc->send_request()</h2>
-<p>The request sending function. Returns boolean TRUE or FALSE based on success for failure, enabling it to be used conditionally.</p>
-
-<h2>$this->xmlrpc->set_debug(TRUE);</h2>
-<p>Enables debugging, which will display a variety of information and error data helpful during development.</p>
-
-
-<h2>$this->xmlrpc->display_error()</h2>
-<p>Returns an error message as a string if your request failed for some reason.</p>
-<code>echo $this->xmlrpc->display_error();</code>
-
-<h2>$this->xmlrpc->display_response()</h2>
-<p>Returns the response from the remote server once request is received. The response will typically be an associative array.</p>
-<code>$this->xmlrpc->display_response();</code>
-
-<h2>$this->xmlrpc->send_error_message()</h2>
-<p>This function lets you send an error message from your server to the client. First parameter is the error number while the second parameter
-is the error message.</p>
-<code>return $this->xmlrpc->send_error_message('123', 'Requested data not available');</code>
-
-<h2>$this->xmlrpc->send_response()</h2>
-<p>Lets you send the response from your server to the client. An array of valid data values must be sent with this method.</p>
-<code>$response = array(<br />
- array(<br />
- 'flerror' => array(FALSE, 'boolean'),<br />
- 'message' => "Thanks for the ping!")<br />
- )<br />
- 'struct');<br />
-return $this->xmlrpc->send_response($response);</code>
-
-
-<a name="datatypes"></a>
-<h2>Data Types</h2>
-
-<p>According to the <a href="http://www.xmlrpc.com/spec">XML-RPC spec</a> there are seven types
-of values that you can send via XML-RPC:</p>
-
-<ul>
-<li><em>int</em> or <em>i4</em></li>
-<li><em>boolean</em></li>
-<li><em>string</em></li>
-<li><em>double</em></li>
-<li><em>dateTime.iso8601</em></li>
-<li><em>base64</em></li>
-<li><em>struct</em> (contains array of values)</li>
-<li><em>array</em> (contains array of values)</li>
-</ul>
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="user_agent.html">User Agent Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="zip.html">Zip Encoding Class</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>XML-RPC and XML-RPC Server Classes : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +XML-RPC and XML-RPC Server Classes +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>XML-RPC and XML-RPC Server Classes</h1> + + +<p>CodeIgniter's XML-RPC classes permit you to send requests to another server, or set up +your own XML-RPC server to receive requests.</p> + + +<h2>What is XML-RPC?</h2> + +<p>Quite simply it is a way for two computers to communicate over the internet using XML. +One computer, which we will call the <dfn>client</dfn>, sends an XML-RPC <strong>request</strong> to +another computer, which we will call the <dfn>server</dfn>. Once the server receives and processes the request it +will send back a <strong>response</strong> to the client.</p> + +<p>For example, using the MetaWeblog API, an XML-RPC Client (usually a desktop publishing tool) will +send a request to an XML-RPC Server running on your site. This request might be a new weblog entry +being sent for publication, or it could be a request for an existing entry for editing. + +When the XML-RPC Server receives this request it will examine it to determine which class/method should be called to process the request. +Once processed, the server will then send back a response message.</p> + +<p>For detailed specifications, you can visit the <a href="http://www.xmlrpc.com/">XML-RPC</a> site.</p> + +<h2>Initializing the Class</h2> + +<p>Like most other classes in CodeIgniter, the XML-RPC and XML-RPCS classes are initialized in your controller using the <dfn>$this->load->library</dfn> function:</p> + +<p>To load the XML-RPC class you will use:</p> +<code>$this->load->library('xmlrpc');</code> +<p>Once loaded, the xml-rpc library object will be available using: <dfn>$this->xmlrpc</dfn></p> + +<p>To load the XML-RPC Server class you will use:</p> +<code> +$this->load->library('xmlrpc');<br /> +$this->load->library('xmlrpcs'); +</code> +<p>Once loaded, the xml-rpcs library object will be available using: <dfn>$this->xmlrpcs</dfn></p> + +<p class="important"><strong>Note:</strong> When using the XML-RPC Server class you must load BOTH the XML-RPC class and the XML-RPC Server class.</p> + + + +<h2>Sending XML-RPC Requests</h2> + +<p>To send a request to an XML-RPC server you must specify the following information:</p> + +<ul> +<li>The URL of the server</li> +<li>The method on the server you wish to call</li> +<li>The <em>request</em> data (explained below).</li> +</ul> + +<p>Here is a basic example that sends a simple Weblogs.com ping to the <a href="http://pingomatic.com/">Ping-o-Matic</a></p> + + +<code>$this->load->library('xmlrpc');<br /> +<br /> +$this->xmlrpc->server('http://rpc.pingomatic.com/', 80);<br /> +$this->xmlrpc->method('weblogUpdates.ping');<br /> + +<br /> +$request = array('My Photoblog', 'http://www.my-site.com/photoblog/');<br /> +$this->xmlrpc->request($request);<br /> +<br /> +if ( ! $this->xmlrpc->send_request())<br /> +{<br /> + echo $this->xmlrpc->display_error();<br /> +}</code> + +<h3>Explanation</h3> + +<p>The above code initializes the XML-RPC class, sets the server URL and method to be called (weblogUpdates.ping). The +request (in this case, the title and URL of your site) is placed into an array for transportation, and +compiled using the request() function. +Lastly, the full request is sent. If the <dfn>send_request()</dfn> method returns false we will display the error message +sent back from the XML-RPC Server.</p> + +<h2>Anatomy of a Request</h2> + +<p>An XML-RPC <dfn>request</dfn> is simply the data you are sending to the XML-RPC server. Each piece of data in a request +is referred to as a <dfn>request parameter</dfn>. The above example has two parameters: +The URL and title of your site. When the XML-RPC server receives your request, it will look for parameters it requires.</p> + +<p>Request parameters must be placed into an array for transportation, and each parameter can be one +of seven data types (strings, numbers, dates, etc.). If your parameters are something other than strings +you will have to include the data type in the request array.</p> + +<p>Here is an example of a simple array with three parameters:</p> + +<code>$request = array('John', 'Doe', 'www.some-site.com');<br /> +$this->xmlrpc->request($request);</code> + +<p>If you use data types other than strings, or if you have several different data types, you will place +each parameter into its own array, with the data type in the second position:</p> + +<code> +$request = array (<br /> + array('John', 'string'),<br /> + array('Doe', 'string'),<br /> + array(FALSE, 'boolean'),<br /> + array(12345, 'int')<br /> + ); +<br /> +$this->xmlrpc->request($request);</code> + +The <a href="#datatypes">Data Types</a> section below has a full list of data types. + + + +<h2>Creating an XML-RPC Server</h2> + +<p>An XML-RPC Server acts as a traffic cop of sorts, waiting for incoming requests and redirecting them to the +appropriate functions for processing.</p> + +<p>To create your own XML-RPC server involves initializing the XML-RPC Server class in your controller where you expect the incoming +request to appear, then setting up an array with mapping instructions so that incoming requests can be sent to the appropriate +class and method for processing.</p> + +<p>Here is an example to illustrate:</p> + +<code> +$this->load->library('xmlrpc');<br /> +$this->load->library('xmlrpcs');<br /> +<br /> +$config['functions']['<var>new_post</var>'] = array('function' => '<dfn>My_blog.new_entry</dfn>'),<br /> +$config['functions']['<var>update_post</var>'] = array('function' => '<dfn>My_blog.update_entry</dfn>');<br /> +$config['object'] = $this;<br /> +<br /> +$this->xmlrpcs->initialize($config);<br /> +$this->xmlrpcs->serve();</code> + +<p>The above example contains an array specifying two method requests that the Server allows. +The allowed methods are on the left side of the array. When either of those are received, they will be mapped to the class and method on the right.</p> + +<p>The '<var>object</var>' key is a special key that you pass an instantiated class object with, which is necessary when the method you are mapping to is not + part of the CodeIgniter super object.</p> + +<p>In other words, if an XML-RPC Client sends a request for the <var>new_post</var> method, your +server will load the <dfn>My_blog</dfn> class and call the <dfn>new_entry</dfn> function. +If the request is for the <var>update_post</var> method, your +server will load the <dfn>My_blog</dfn> class and call the <dfn>update_entry</dfn> function.</p> + +<p>The function names in the above example are arbitrary. You'll decide what they should be called on your server, +or if you are using standardized APIs, like the Blogger or MetaWeblog API, you'll use their function names.</p> + +<h2>Processing Server Requests</h2> + +<p>When the XML-RPC Server receives a request and loads the class/method for processing, it will pass +an object to that method containing the data sent by the client.</p> + +<p>Using the above example, if the <var>new_post</var> method is requested, the server will expect a class +to exist with this prototype:</p> + +<code>class <kbd>My_blog</kbd> extends Controller {<br /> +<br /> + function <kbd>new_post</kbd>(<var>$request</var>)<br /> + {<br /> + <br /> + }<br /> +} +</code> + +<p>The <var>$request</var> variable is an object compiled by the Server, which contains the data sent by the XML-RPC Client. +Using this object you will have access to the <em>request parameters</em> enabling you to process the request. When +you are done you will send a <dfn>Response</dfn> back to the Client.</p> + +<p>Below is a real-world example, using the Blogger API. One of the methods in the Blogger API is <dfn>getUserInfo()</dfn>. +Using this method, an XML-RPC Client can send the Server a username and password, in return the Server sends +back information about that particular user (nickname, user ID, email address, etc.). Here is how the processing +function might look:</p> + + +<code>class <kbd>My_blog</kbd> extends Controller {<br /> +<br /> + function <kbd>getUserInfo</kbd>(<var>$request</var>)<br /> + {<br /> + + $username = 'smitty';<br /> + $password = 'secretsmittypass';<br /><br /> + + $this->load->library('xmlrpc');<br /> + <br /> + $parameters = $request->output_parameters();<br /> + <br /> + if ($parameters['1'] != $username AND $parameters['2'] != $password)<br /> + {<br /> + return $this->xmlrpc->send_error_message('100', 'Invalid Access');<br /> + }<br /> + <br /> + $response = array(array('nickname' => array('Smitty','string'),<br /> + 'userid' => array('99','string'),<br /> + 'url' => array('http://yoursite.com','string'),<br /> + 'email' => array('jsmith@yoursite.com','string'),<br /> + 'lastname' => array('Smith','string'),<br /> + 'firstname' => array('John','string')<br /> + ),<br /> + 'struct');<br /> +<br /> + return $this->xmlrpc->send_response($response);<br /> + }<br /> +} +</code> + +<h3>Notes:</h3> +<p>The <dfn>output_parameters()</dfn> function retrieves an indexed array corresponding to the request parameters sent by the client. +In the above example, the output parameters will be the username and password.</p> + +<p>If the username and password sent by the client were not valid, and error message is returned using <dfn>send_error_message()</dfn>.</p> + +<p>If the operation was successful, the client will be sent back a response array containing the user's info.</p> + + +<h2>Formatting a Response</h2> + +<p>Similar to <em>Requests</em>, <em>Responses</em> must be formatted as an array. However, unlike requests, a response is an array +<strong>that contains a single item</strong>. This item can be an array with several additional arrays, but there +can be only one primary array index. In other words, the basic prototype is this:</p> + +<code>$response = array('Response data', 'array');</code> + +<p>Responses, however, usually contain multiple pieces of information. In order to accomplish this we must put the response into its own +array so that the primary array continues to contain a single piece of data. Here's an example showing how this might be accomplished:</p> + +<code> +$response = array (<br /> + array(<br /> + 'first_name' => array('John', 'string'),<br /> + 'last_name' => array('Doe', 'string'),<br /> + 'member_id' => array(123435, 'int'),<br /> + 'todo_list' => array(array('clean house', 'call mom', 'water plants'), 'array'),<br /> + ),<br /> + 'struct'<br /> + ); +</code> + +<p class="important">Notice that the above array is formatted as a <dfn>struct</dfn>. This is the most common data type for responses.</p> + +<p>As with Requests, a response can be one of the seven data types listed in the <a href="#datatypes">Data Types</a> section.</p> + + +<h2>Sending an Error Response</h2> + +<p>If you need to send the client an error response you will use the following:</p> + +<code>return $this->xmlrpc->send_error_message('123', 'Requested data not available');</code> + +<p>The first parameter is the error number while the second parameter is the error message.</p> + + + + + + +<h2>Creating Your Own Client and Server</h2> + +<p>To help you understand everything we've covered thus far, let's create a couple controllers that act as +XML-RPC Client and Server. You'll use the Client to send a request to the Server and receive a response.</p> + +<h3>The Client</h3> + +<p>Using a text editor, create a controller called <dfn>xmlrpc_client.php</dfn>. +In it, place this code and save it to your <samp>applications/controllers/</samp> folder:</p> + +<textarea class="textarea" style="width:100%" cols="50" rows="32"><?php + +class Xmlrpc_client extends Controller { + + function index() + { + $this->load->helper('url'); + $server_url = site_url('xmlrpc_server'); + + $this->load->library('xmlrpc'); + + $this->xmlrpc->server($server_url, 80); + $this->xmlrpc->method('Greetings'); + + $request = array('How is it going?'); + $this->xmlrpc->request($request); + + if ( ! $this->xmlrpc->send_request()) + { + echo $this->xmlrpc->display_error(); + } + else + { + echo '<pre>'; + print_r($this->xmlrpc->display_response()); + echo '</pre>'; + } + } +} +?></textarea> + +<p>Note: In the above code we are using a "url helper". You can find more information in the <a href="../general/helpers.html">Helpers Functions</a> page.</p> + +<h3>The Server</h3> + +<p>Using a text editor, create a controller called <dfn>xmlrpc_server.php</dfn>. +In it, place this code and save it to your <samp>applications/controllers/</samp> folder:</p> + +<textarea class="textarea" style="width:100%" cols="50" rows="30"><?php + +class Xmlrpc_server extends Controller { + + function index() + { + $this->load->library('xmlrpc'); + $this->load->library('xmlrpcs'); + + $config['functions']['Greetings'] = array('function' => 'Xmlrpc_server.process'); + + $this->xmlrpcs->initialize($config); + $this->xmlrpcs->serve(); + } + + + function process($request) + { + $parameters = $request->output_parameters(); + + $response = array( + array( + 'you_said' => $parameters['0'], + 'i_respond' => 'Not bad at all.'), + 'struct'); + + return $this->xmlrpc->send_response($response); + } +} +?></textarea> + +<h3>Try it!</h3> + +<p>Now visit the your site using a URL similar to this:</p> +<code>example.com/index.php/<var>xmlrpc_client</var>/</code> + +<p>You should now see the message you sent to the server, and its response back to you.</p> + +<p>The client you created sends a message ("How's is going?") to the server, along with a request for the "Greetings" method. +The Server receives the request and maps it to the "process" function, where a response is sent back.</p> + +<h2>Using Associative Arrays In a Request Parameter</h2> + +<p>If you wish to use an associative array in your method parameters you will need to use a struct datatype:</p> + +<code>$request = array(<br /> + array(<br /> + // Param 0<br /> + array(<br /> + 'name'=>'John'<br /> + ),<br /> + 'struct'<br /> + ),<br /> + array(<br /> + // Param 1<br /> + array(<br /> + 'size'=>'large',<br /> + 'shape'=>'round'<br /> + ),<br /> + 'struct'<br /> + )<br /> + );<br /> + $this->xmlrpc->request($request);</code> + +<p>You can retrieve the associative array when processing the request in the Server.</p> + +<code>$parameters = $request->output_parameters();<br /> + $name = $parameters['0']['name'];<br /> + $size = $parameters['1']['size'];<br /> + $size = $parameters['1']['shape']; </code> + +<h1>XML-RPC Function Reference</h1> + +<h2>$this->xmlrpc->server()</h2> +<p>Sets the URL and port number of the server to which a request is to be sent:</p> +<code>$this->xmlrpc->server('http://www.sometimes.com/pings.php', 80);</code> + +<h2>$this->xmlrpc->timeout()</h2> +<p>Set a time out period (in seconds) after which the request will be canceled:</p> +<code>$this->xmlrpc->timeout(6);</code> + +<h2>$this->xmlrpc->method()</h2> +<p>Sets the method that will be requested from the XML-RPC server:</p> +<code>$this->xmlrpc->method('<var>method</var>');</code> + +<p>Where <var>method</var> is the name of the method.</p> + +<h2>$this->xmlrpc->request()</h2> +<p>Takes an array of data and builds request to be sent to XML-RPC server:</p> +<code>$request = array(array('My Photoblog', 'string'), 'http://www.yoursite.com/photoblog/');<br /> +$this->xmlrpc->request($request);</code> + +<h2>$this->xmlrpc->send_request()</h2> +<p>The request sending function. Returns boolean TRUE or FALSE based on success for failure, enabling it to be used conditionally.</p> + +<h2>$this->xmlrpc->set_debug(TRUE);</h2> +<p>Enables debugging, which will display a variety of information and error data helpful during development.</p> + + +<h2>$this->xmlrpc->display_error()</h2> +<p>Returns an error message as a string if your request failed for some reason.</p> +<code>echo $this->xmlrpc->display_error();</code> + +<h2>$this->xmlrpc->display_response()</h2> +<p>Returns the response from the remote server once request is received. The response will typically be an associative array.</p> +<code>$this->xmlrpc->display_response();</code> + +<h2>$this->xmlrpc->send_error_message()</h2> +<p>This function lets you send an error message from your server to the client. First parameter is the error number while the second parameter +is the error message.</p> +<code>return $this->xmlrpc->send_error_message('123', 'Requested data not available');</code> + +<h2>$this->xmlrpc->send_response()</h2> +<p>Lets you send the response from your server to the client. An array of valid data values must be sent with this method.</p> +<code>$response = array(<br /> + array(<br /> + 'flerror' => array(FALSE, 'boolean'),<br /> + 'message' => "Thanks for the ping!")<br /> + )<br /> + 'struct');<br /> +return $this->xmlrpc->send_response($response);</code> + + +<a name="datatypes"></a> +<h2>Data Types</h2> + +<p>According to the <a href="http://www.xmlrpc.com/spec">XML-RPC spec</a> there are seven types +of values that you can send via XML-RPC:</p> + +<ul> +<li><em>int</em> or <em>i4</em></li> +<li><em>boolean</em></li> +<li><em>string</em></li> +<li><em>double</em></li> +<li><em>dateTime.iso8601</em></li> +<li><em>base64</em></li> +<li><em>struct</em> (contains array of values)</li> +<li><em>array</em> (contains array of values)</li> +</ul> + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="user_agent.html">User Agent Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="zip.html">Zip Encoding Class</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file diff --git a/user_guide/libraries/zip.html b/user_guide/libraries/zip.html index c789c85ff..ebd5b49a6 100644 --- a/user_guide/libraries/zip.html +++ b/user_guide/libraries/zip.html @@ -1,278 +1,278 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>Zip Encoding Class : CodeIgniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
-
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='ExpressionEngine Dev Team' />
-<meta name='description' content='CodeIgniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
-<a href="../index.html">User Guide Home</a> ›
-Zip Encoding Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-<h1>Zip Encoding Class</h1>
-<p>CodeIgniter's Zip Encoding Class classes permit you to create Zip archives. Archives can be downloaded to your
-desktop or saved to a directory.</p>
-
-
-<h2>Initializing the Class</h2>
-<p>Like most other classes in CodeIgniter, the Zip class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
-
-<code>$this->load->library('zip');</code>
-<p>Once loaded, the Zip library object will be available using: <dfn>$this->zip</dfn></p>
-
-
-<h2>Usage Example</h2>
-
-<p>This example demonstrates how to compress a file, save it to a folder on your server, and download it to your desktop.</p>
-
-<code>
-$name = 'mydata1.txt';<br />
-$data = 'A Data String!';<br />
-<br />
-$this->zip->add_data($name, $data);<br />
-<br />
-// Write the zip file to a folder on your server. Name it "my_backup.zip"<br />
-$this->zip->archive('/path/to/directory/my_backup.zip');
-<br /><br />
- // Download the file to your desktop. Name it "my_backup.zip"<br />
-$this->zip->download('my_backup.zip');
-</code>
-
-<h1>Function Reference</h1>
-
-<h2>$this->zip->add_data()</h2>
-
-<p>Permits you to add data to the Zip archive. The first parameter must contain the name you would like
-given to the file, the second parameter must contain the file data as a string:</p>
-
-<code>
-$name = 'my_bio.txt';<br />
-$data = 'I was born in an elevator...';<br />
-<br />
-$this->zip->add_data($name, $data);
-</code>
-
-<p>You are allowed multiple calls to this function in order to
-add several files to your archive. Example:</p>
-
-<code>
-$name = 'mydata1.txt';<br />
-$data = 'A Data String!';<br />
-$this->zip->add_data($name, $data);<br />
-<br />
-$name = 'mydata2.txt';<br />
-$data = 'Another Data String!';<br />
-$this->zip->add_data($name, $data);<br />
-</code>
-
-<p>Or you can pass multiple files using an array:</p>
-
-<code>
-$data = array(<br />
- 'mydata1.txt' => 'A Data String!',<br />
- 'mydata2.txt' => 'Another Data String!'<br />
- );<br />
-<br />
-$this->zip->add_data($data);<br />
-<br />
-$this->zip->download('my_backup.zip');
-</code>
-
-<p>If you would like your compressed data organized into sub-folders, include the path as part of the filename:</p>
-
-<code>
-$name = '<kbd>personal/</kbd>my_bio.txt';<br />
-$data = 'I was born in an elevator...';<br />
-<br />
-$this->zip->add_data($name, $data);
-</code>
-
-<p>The above example will place <dfn>my_bio.txt</dfn> inside a folder called <kbd>personal</kbd>.</p>
-
-
-<h2>$this->zip->add_dir()</h2>
-
-<p>Permits you to add a directory. Usually this function is unnecessary since you can place your data into folders when
-using <dfn>$this->zip->add_data()</dfn>, but if you would like to create an empty folder you can do so. Example:</p>
-
-<code>$this->zip->add_dir('myfolder'); // Creates a folder called "myfolder"</code>
-
-
-
-<h2>$this->zip->read_file()</h2>
-
-<p>Permits you to compress a file that already exists somewhere on your server. Supply a file path and the zip class will
-read it and add it to the archive:</p>
-
-<code>
-$path = '/path/to/photo.jpg';<br /><br />
-$this->zip->read_file($path);
-<br /><br />
- // Download the file to your desktop. Name it "my_backup.zip"<br />
-$this->zip->download('my_backup.zip');
-</code>
-
-<p>If you would like the Zip archive to maintain the directory structure of the file in it, pass <kbd>TRUE</kbd> (boolean) in the
-second parameter. Example:</p>
-
-
-<code>
-$path = '/path/to/photo.jpg';<br /><br />
-$this->zip->read_file($path, <kbd>TRUE</kbd>);
-<br /><br />
- // Download the file to your desktop. Name it "my_backup.zip"<br />
-$this->zip->download('my_backup.zip');
-</code>
-
-<p>In the above example, <dfn>photo.jpg</dfn> will be placed inside two folders: <kbd>path/to/</kbd></p>
-
-
-
-<h2>$this->zip->read_dir()</h2>
-
-<p>Permits you to compress a folder (and its contents) that already exists somewhere on your server. Supply a file path to the
-directory and the zip class will recursively read it and recreate it as a Zip archive. All files contained within the
-supplied path will be encoded, as will any sub-folders contained within it. Example:</p>
-
-<code>
-$path = '/path/to/your/directory/';<br /><br />
-$this->zip->read_dir($path);
-<br /><br />
- // Download the file to your desktop. Name it "my_backup.zip"<br />
-$this->zip->download('my_backup.zip');
-</code>
-
-
-
-
-<h2>$this->zip->archive()</h2>
-
-<p>Writes the Zip-encoded file to a directory on your server. Submit a valid server path ending in the file name. Make sure the
-directory is writable (666 or 777 is usually OK). Example:</p>
-
-<code>$this->zip->archive('/path/to/folder/myarchive.zip'); // Creates a file named myarchive.zip</code>
-
-
-<h2>$this->zip->download()</h2>
-
-<p>Causes the Zip file to be downloaded from your server. The function must be passed the name you would like the zip file called.
-Example:</p>
-
-<code>$this->zip->download('latest_stuff.zip'); // File will be named "latest_stuff.zip"</code>
-
-<p class="important"><strong>Note:</strong> Do not display any data in the controller in which you call this function since it sends various server headers
-that cause the download to happen and the file to be treated as binary.</p>
-
-
-<h2>$this->zip->get_zip()</h2>
-
-<p>Returns the Zip-compressed file data. Generally you will not need this function unless you want to do something unique with the data.
-Example:</p>
-
-<code>
-$name = 'my_bio.txt';<br />
-$data = 'I was born in an elevator...';<br />
-<br />
-$this->zip->add_data($name, $data);<br /><br />
-
-$zip_file = $this->zip->get_zip();
-</code>
-
-
-<h2>$this->zip->clear_data()</h2>
-
-<p>The Zip class caches your zip data so that it doesn't need to recompile the Zip archive for each function you use above.
-If, however, you need to create multiple Zips, each with different data, you can clear the cache between calls. Example:</p>
-
-<code>
-$name = 'my_bio.txt';<br />
-$data = 'I was born in an elevator...';<br />
-<br />
-$this->zip->add_data($name, $data);<br />
-$zip_file = $this->zip->get_zip();<br />
-<br />
-<kbd>$this->zip->clear_data();</kbd>
-<br /><br />
-
-$name = 'photo.jpg';<br />
-$this->zip->read_file("/path/to/photo.jpg"); // Read the file's contents<br />
-<br /><br />
-$this->zip->download('myphotos.zip');
-</code>
-
-
-
-
-
-
-
-
-
-
-
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic: <a href="xmlrpc.html"> XML-RPC Class</a>
- ·
-<a href="#top">Top of Page</a> ·
-<a href="../index.html">User Guide Home</a> ·
-Next Topic: <a href="../helpers/array_helper.html">Array Helper</a>
-</p>
-<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
-</div>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>Zip Encoding Class : CodeIgniter User Guide</title> + +<style type='text/css' media='all'>@import url('../userguide.css');</style> +<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' /> + +<script type="text/javascript" src="../nav/nav.js"></script> +<script type="text/javascript" src="../nav/prototype.lite.js"></script> +<script type="text/javascript" src="../nav/moo.fx.js"></script> +<script type="text/javascript" src="../nav/user_guide_menu.js"></script> + +<meta http-equiv='expires' content='-1' /> +<meta http-equiv= 'pragma' content='no-cache' /> +<meta name='robots' content='all' /> +<meta name='author' content='ExpressionEngine Dev Team' /> +<meta name='description' content='CodeIgniter User Guide' /> + +</head> +<body> + +<!-- START NAVIGATION --> +<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div> +<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div> +<div id="masthead"> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td><h1>CodeIgniter User Guide Version 1.7</h1></td> +<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td> +</tr> +</table> +</div> +<!-- END NAVIGATION --> + + +<!-- START BREADCRUMB --> +<table cellpadding="0" cellspacing="0" border="0" style="width:100%"> +<tr> +<td id="breadcrumb"> +<a href="http://codeigniter.com/">CodeIgniter Home</a> › +<a href="../index.html">User Guide Home</a> › +Zip Encoding Class +</td> +<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td> +</tr> +</table> +<!-- END BREADCRUMB --> + +<br clear="all" /> + + +<!-- START CONTENT --> +<div id="content"> + + +<h1>Zip Encoding Class</h1> +<p>CodeIgniter's Zip Encoding Class classes permit you to create Zip archives. Archives can be downloaded to your +desktop or saved to a directory.</p> + + +<h2>Initializing the Class</h2> +<p>Like most other classes in CodeIgniter, the Zip class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p> + +<code>$this->load->library('zip');</code> +<p>Once loaded, the Zip library object will be available using: <dfn>$this->zip</dfn></p> + + +<h2>Usage Example</h2> + +<p>This example demonstrates how to compress a file, save it to a folder on your server, and download it to your desktop.</p> + +<code> +$name = 'mydata1.txt';<br /> +$data = 'A Data String!';<br /> +<br /> +$this->zip->add_data($name, $data);<br /> +<br /> +// Write the zip file to a folder on your server. Name it "my_backup.zip"<br /> +$this->zip->archive('/path/to/directory/my_backup.zip'); +<br /><br /> + // Download the file to your desktop. Name it "my_backup.zip"<br /> +$this->zip->download('my_backup.zip'); +</code> + +<h1>Function Reference</h1> + +<h2>$this->zip->add_data()</h2> + +<p>Permits you to add data to the Zip archive. The first parameter must contain the name you would like +given to the file, the second parameter must contain the file data as a string:</p> + +<code> +$name = 'my_bio.txt';<br /> +$data = 'I was born in an elevator...';<br /> +<br /> +$this->zip->add_data($name, $data); +</code> + +<p>You are allowed multiple calls to this function in order to +add several files to your archive. Example:</p> + +<code> +$name = 'mydata1.txt';<br /> +$data = 'A Data String!';<br /> +$this->zip->add_data($name, $data);<br /> +<br /> +$name = 'mydata2.txt';<br /> +$data = 'Another Data String!';<br /> +$this->zip->add_data($name, $data);<br /> +</code> + +<p>Or you can pass multiple files using an array:</p> + +<code> +$data = array(<br /> + 'mydata1.txt' => 'A Data String!',<br /> + 'mydata2.txt' => 'Another Data String!'<br /> + );<br /> +<br /> +$this->zip->add_data($data);<br /> +<br /> +$this->zip->download('my_backup.zip'); +</code> + +<p>If you would like your compressed data organized into sub-folders, include the path as part of the filename:</p> + +<code> +$name = '<kbd>personal/</kbd>my_bio.txt';<br /> +$data = 'I was born in an elevator...';<br /> +<br /> +$this->zip->add_data($name, $data); +</code> + +<p>The above example will place <dfn>my_bio.txt</dfn> inside a folder called <kbd>personal</kbd>.</p> + + +<h2>$this->zip->add_dir()</h2> + +<p>Permits you to add a directory. Usually this function is unnecessary since you can place your data into folders when +using <dfn>$this->zip->add_data()</dfn>, but if you would like to create an empty folder you can do so. Example:</p> + +<code>$this->zip->add_dir('myfolder'); // Creates a folder called "myfolder"</code> + + + +<h2>$this->zip->read_file()</h2> + +<p>Permits you to compress a file that already exists somewhere on your server. Supply a file path and the zip class will +read it and add it to the archive:</p> + +<code> +$path = '/path/to/photo.jpg';<br /><br /> +$this->zip->read_file($path); +<br /><br /> + // Download the file to your desktop. Name it "my_backup.zip"<br /> +$this->zip->download('my_backup.zip'); +</code> + +<p>If you would like the Zip archive to maintain the directory structure of the file in it, pass <kbd>TRUE</kbd> (boolean) in the +second parameter. Example:</p> + + +<code> +$path = '/path/to/photo.jpg';<br /><br /> +$this->zip->read_file($path, <kbd>TRUE</kbd>); +<br /><br /> + // Download the file to your desktop. Name it "my_backup.zip"<br /> +$this->zip->download('my_backup.zip'); +</code> + +<p>In the above example, <dfn>photo.jpg</dfn> will be placed inside two folders: <kbd>path/to/</kbd></p> + + + +<h2>$this->zip->read_dir()</h2> + +<p>Permits you to compress a folder (and its contents) that already exists somewhere on your server. Supply a file path to the +directory and the zip class will recursively read it and recreate it as a Zip archive. All files contained within the +supplied path will be encoded, as will any sub-folders contained within it. Example:</p> + +<code> +$path = '/path/to/your/directory/';<br /><br /> +$this->zip->read_dir($path); +<br /><br /> + // Download the file to your desktop. Name it "my_backup.zip"<br /> +$this->zip->download('my_backup.zip'); +</code> + + + + +<h2>$this->zip->archive()</h2> + +<p>Writes the Zip-encoded file to a directory on your server. Submit a valid server path ending in the file name. Make sure the +directory is writable (666 or 777 is usually OK). Example:</p> + +<code>$this->zip->archive('/path/to/folder/myarchive.zip'); // Creates a file named myarchive.zip</code> + + +<h2>$this->zip->download()</h2> + +<p>Causes the Zip file to be downloaded from your server. The function must be passed the name you would like the zip file called. +Example:</p> + +<code>$this->zip->download('latest_stuff.zip'); // File will be named "latest_stuff.zip"</code> + +<p class="important"><strong>Note:</strong> Do not display any data in the controller in which you call this function since it sends various server headers +that cause the download to happen and the file to be treated as binary.</p> + + +<h2>$this->zip->get_zip()</h2> + +<p>Returns the Zip-compressed file data. Generally you will not need this function unless you want to do something unique with the data. +Example:</p> + +<code> +$name = 'my_bio.txt';<br /> +$data = 'I was born in an elevator...';<br /> +<br /> +$this->zip->add_data($name, $data);<br /><br /> + +$zip_file = $this->zip->get_zip(); +</code> + + +<h2>$this->zip->clear_data()</h2> + +<p>The Zip class caches your zip data so that it doesn't need to recompile the Zip archive for each function you use above. +If, however, you need to create multiple Zips, each with different data, you can clear the cache between calls. Example:</p> + +<code> +$name = 'my_bio.txt';<br /> +$data = 'I was born in an elevator...';<br /> +<br /> +$this->zip->add_data($name, $data);<br /> +$zip_file = $this->zip->get_zip();<br /> +<br /> +<kbd>$this->zip->clear_data();</kbd> +<br /><br /> + +$name = 'photo.jpg';<br /> +$this->zip->read_file("/path/to/photo.jpg"); // Read the file's contents<br /> +<br /><br /> +$this->zip->download('myphotos.zip'); +</code> + + + + + + + + + + + + + +</div> +<!-- END CONTENT --> + + +<div id="footer"> +<p> +Previous Topic: <a href="xmlrpc.html"> XML-RPC Class</a> + · +<a href="#top">Top of Page</a> · +<a href="../index.html">User Guide Home</a> · +Next Topic: <a href="../helpers/array_helper.html">Array Helper</a> +</p> +<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p> +</div> + +</body> </html>
\ No newline at end of file |