admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
| 2 | <html>
|
| 3 | <head>
|
| 4 |
|
| 5 | <title>Code Igniter User Guide</title>
|
| 6 |
|
| 7 | <style type='text/css' media='all'>@import url('../userguide.css');</style>
|
| 8 | <link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
|
| 9 |
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 10 | <script type="text/javascript" src="../nav/nav.js"></script>
|
admin | 2296fc3 | 2006-09-27 21:07:02 +0000 | [diff] [blame] | 11 | <script type="text/javascript" src="../nav/prototype.lite.js"></script>
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 12 | <script type="text/javascript" src="../nav/moo.fx.js"></script>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 13 | <script type="text/javascript">
|
| 14 | window.onload = function() {
|
| 15 | myHeight = new fx.Height('nav', {duration: 400});
|
| 16 | myHeight.hide();
|
| 17 | }
|
| 18 | </script>
|
| 19 |
|
| 20 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
| 21 | <meta http-equiv='expires' content='-1' />
|
| 22 | <meta http-equiv= 'pragma' content='no-cache' />
|
| 23 | <meta name='robots' content='all' />
|
| 24 | <meta name='author' content='Rick Ellis' />
|
| 25 | <meta name='description' content='Code Igniter User Guide' />
|
| 26 |
|
| 27 | </head>
|
| 28 | <body>
|
| 29 |
|
| 30 | <!-- START NAVIGATION -->
|
| 31 | <div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
|
| 32 | <div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
|
| 33 | <div id="masthead">
|
| 34 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 35 | <tr>
|
admin | 10c3f41 | 2006-10-08 07:21:12 +0000 | [diff] [blame] | 36 | <td><h1>Code Igniter User Guide Version 1.5.0b1</h1></td>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 37 | <td id="breadcrumb_right"><a href="../toc.html">Full Table of Contents</a></td>
|
| 38 | </tr>
|
| 39 | </table>
|
| 40 | </div>
|
| 41 | <!-- END NAVIGATION -->
|
| 42 |
|
| 43 |
|
| 44 | <!-- START BREADCRUMB -->
|
| 45 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 46 | <tr>
|
| 47 | <td id="breadcrumb">
|
| 48 | <a href="http://www.codeigniter.com/">Code Igniter Home</a> ›
|
| 49 | <a href="../index.html">User Guide Home</a> ›
|
| 50 | Loader Class
|
| 51 | </td>
|
| 52 | <td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="www.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>
|
| 53 | </tr>
|
| 54 | </table>
|
| 55 | <!-- END BREADCRUMB -->
|
| 56 |
|
| 57 | <br clear="all" />
|
| 58 |
|
| 59 |
|
| 60 | <!-- START CONTENT -->
|
| 61 | <div id="content">
|
| 62 |
|
| 63 |
|
| 64 | <h1>Loader Class</h1>
|
| 65 |
|
| 66 | <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>,
|
| 67 | <a href="../general/helpers.html">Helpers</a>, <a href="../general/plugins.html">Plugins</a>, or your own files.</p>
|
| 68 |
|
| 69 | <p class="important"><strong>Note:</strong> This class is initialized automatically by the system so there is no need to do it manually.</p>
|
| 70 |
|
| 71 | <p>The following functions are available in this class:</p>
|
| 72 |
|
| 73 |
|
| 74 |
|
admin | 2f0bac8 | 2006-10-09 17:36:45 +0000 | [diff] [blame] | 75 | <h2>$this->load->library('<var>class_name</var>')</h2>
|
| 76 |
|
| 77 | <p>This function is used to load core classes. Where <var>class_name</var> is the name of the class you want to load.
|
| 78 | Note: We use the terms "class" and "library" interchangeably.</p>
|
| 79 |
|
| 80 | <p>For example, if you would like to send email with Code Igniter, the first step is to load the email class within your controller:</p>
|
| 81 |
|
| 82 | <code>$this->load->library('email');</code>
|
| 83 |
|
| 84 | <p>Once loaded, the library will be ready for use, using <kbd>$this->email-></kbd><samp><em>some_function</em>()</samp>.
|
| 85 |
|
| 86 | Each library is described in detail in its own page, so please read theinformation regarding each one you would like to use.</p>
|
| 87 |
|
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 88 | <p>Parameters can be passed to the library via an array in the second parameter.
|
| 89 |
|
| 90 |
|
| 91 |
|
admin | 2f0bac8 | 2006-10-09 17:36:45 +0000 | [diff] [blame] | 92 | <p>If you would like your libraries assigned to a different variable name then the default you can specify the name in the second paramter:</p>
|
| 93 |
|
| 94 | <code>
|
| 95 | $this->load->library('email', 'E'); // Assigns the email object to "E"<br />
|
| 96 | <br />
|
| 97 | <kbd>$this->E-></kbd><samp><em>some_function</em>()</samp>
|
| 98 | </code>
|
| 99 |
|
| 100 |
|
| 101 |
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 102 | <h2>$this->load->view('<var>file_name</var>', <samp>$data</samp>, <kbd>true/false</kbd>)</h2>
|
| 103 |
|
| 104 | <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
|
| 105 | user guide it is recommended that you do since it shows you how this function is typically used.</p>
|
| 106 |
|
| 107 | <p>The first parameter is required. It is the name of the view file you would like to load.</p>
|
| 108 |
|
| 109 | <p>The second <strong>optional</strong> parameter can take
|
| 110 | 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
|
| 111 | convert to variables that can be used in your view files. Again, read the <a href="../general/views.html">Views</a> page to learn
|
| 112 | how this might be useful.</p>
|
| 113 |
|
| 114 | <p>The third <strong>optional</strong> parameter lets you change the behavior of the function so that it returns data as a string
|
| 115 | rather than sending it to your browser. This can be useful if you want to process the data in some way. If you
|
| 116 | set the parameter to <kbd>true</kbd> (boolean) it will return data. The default behavior is <kbd>false</kbd>, which sends it
|
| 117 | to your browser. Remember to assign it to a variable if you wan the data returned:</p>
|
| 118 |
|
| 119 | <code>$string = $this->load->view('<var>myfile</var>', '', <kbd>true</kbd>);</code>
|
| 120 |
|
| 121 |
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 122 | <h2>$this->load->database('<var>options</var>', <kbd>true/false</kbd>)</h2>
|
| 123 |
|
| 124 | <p>This function lets you load the database class. The two parameters are <strong>optional</strong>. Please see the
|
| 125 | <a href="./database/index.html">database</a> section for more info.</p>
|
| 126 |
|
| 127 |
|
| 128 | <h2>$this->load->scaffolding('<var>table_name</var>')</h2>
|
| 129 |
|
| 130 | <p>This function lets you enable scaffolding. Please see the
|
| 131 | <a href="../general/scaffolding.html">scaffolding</a> section for more info.</p>
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 | <h2>$this->load->vars(<samp>$array</samp>)</h2>
|
| 136 |
|
| 137 | <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.
|
| 138 | This function produces the same result as using the second parameter of the <dfn>$this->load->view()</dfn> function above. The reason you might
|
| 139 | want to use this function independently is if you would like to set some global variables in the constructor of your controller
|
| 140 | 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
|
| 141 | and merged into one array for conversion to variables.
|
| 142 | </p>
|
| 143 |
|
| 144 |
|
| 145 | <h2>$this->load->helper('<var>file_name</var>')</h2>
|
| 146 | <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>
|
| 147 |
|
| 148 |
|
| 149 | <h2>$this->load->plugin('<var>file_name</var>')</h2>
|
| 150 | <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>
|
| 151 |
|
| 152 | <h2>$this->load->file('<var>filepath/filename</var>', <kbd>true/false</kbd>)</h2>
|
| 153 | <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.
|
| 154 | 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)
|
| 155 | it will instead return the data as a string.</p>
|
| 156 |
|
| 157 |
|
| 158 | <h2>$this->load->lang('<var>file_name</var>')</h2>
|
| 159 | <p>This function is an alias of the <a href="language.html">language loading function</a>: $this->lang->load()</p>
|
| 160 |
|
| 161 | <h2>$this->load->config('<var>file_name</var>')</h2>
|
| 162 | <p>This function is an alias of the <a href="config.html">config file loading function</a>: $this->config->load()</p>
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 | </div>
|
| 168 | <!-- END CONTENT -->
|
| 169 |
|
| 170 |
|
| 171 | <div id="footer">
|
| 172 | <p>
|
| 173 | Previous Topic: <a href="input.html">Input Class</a>
|
| 174 | ·
|
| 175 | <a href="#top">Top of Page</a> ·
|
| 176 | <a href="../index.html">User Guide Home</a> ·
|
| 177 | Next Topic: <a href="language.html">Language Class</a>
|
| 178 | <p>
|
| 179 | <p><a href="http://www.codeigniter.com">Code Igniter</a> · Copyright © 2006 · <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
|
| 180 | </div>
|
| 181 |
|
| 182 | </body>
|
| 183 | </html> |