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">
|
Derek Allard | afd99ac | 2008-01-19 19:59:14 +0000 | [diff] [blame] | 2 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 3 | <head>
|
| 4 |
|
Derek Allard | 8039d4c | 2008-05-31 02:47:56 +0000 | [diff] [blame] | 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
Derek Jones | fd93d22 | 2008-05-06 15:18:50 +0000 | [diff] [blame] | 6 | <title>Loader Class : CodeIgniter User Guide</title>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 7 |
|
| 8 | <style type='text/css' media='all'>@import url('../userguide.css');</style>
|
| 9 | <link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
|
| 10 |
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 11 | <script type="text/javascript" src="../nav/nav.js"></script>
|
admin | 2296fc3 | 2006-09-27 21:07:02 +0000 | [diff] [blame] | 12 | <script type="text/javascript" src="../nav/prototype.lite.js"></script>
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 13 | <script type="text/javascript" src="../nav/moo.fx.js"></script>
|
Derek Allard | b341237 | 2007-10-25 12:15:16 +0000 | [diff] [blame] | 14 | <script type="text/javascript" src="../nav/user_guide_menu.js"></script>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 15 |
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 16 | <meta http-equiv='expires' content='-1' />
|
| 17 | <meta http-equiv= 'pragma' content='no-cache' />
|
| 18 | <meta name='robots' content='all' />
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 19 | <meta name='author' content='ExpressionEngine Dev Team' />
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 20 | <meta name='description' content='CodeIgniter User Guide' />
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 21 |
|
| 22 | </head>
|
| 23 | <body>
|
| 24 |
|
| 25 | <!-- START NAVIGATION -->
|
| 26 | <div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
|
| 27 | <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>
|
| 28 | <div id="masthead">
|
| 29 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 30 | <tr>
|
Derek Jones | 6b7b11f | 2008-05-06 16:07:27 +0000 | [diff] [blame] | 31 | <td><h1>CodeIgniter User Guide Version 1.6.2</h1></td>
|
admin | c0d5d52 | 2006-10-30 19:40:35 +0000 | [diff] [blame] | 32 | <td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 33 | </tr>
|
| 34 | </table>
|
| 35 | </div>
|
| 36 | <!-- END NAVIGATION -->
|
| 37 |
|
| 38 |
|
| 39 | <!-- START BREADCRUMB -->
|
| 40 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 41 | <tr>
|
| 42 | <td id="breadcrumb">
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 43 | <a href="http://codeigniter.com/">CodeIgniter Home</a> ›
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 44 | <a href="../index.html">User Guide Home</a> ›
|
| 45 | Loader Class
|
| 46 | </td>
|
Derek Allard | bc03091 | 2007-06-24 18:25:29 +0000 | [diff] [blame] | 47 | <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>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 48 | </tr>
|
| 49 | </table>
|
| 50 | <!-- END BREADCRUMB -->
|
| 51 |
|
| 52 | <br clear="all" />
|
| 53 |
|
| 54 |
|
| 55 | <!-- START CONTENT -->
|
| 56 | <div id="content">
|
| 57 |
|
| 58 |
|
| 59 | <h1>Loader Class</h1>
|
| 60 |
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 61 | <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>,
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 62 | <a href="../general/helpers.html">Helpers</a>, <a href="../general/plugins.html">Plugins</a>, or your own files.</p>
|
| 63 |
|
| 64 | <p class="important"><strong>Note:</strong> This class is initialized automatically by the system so there is no need to do it manually.</p>
|
| 65 |
|
| 66 | <p>The following functions are available in this class:</p>
|
| 67 |
|
| 68 |
|
| 69 |
|
admin | 2f0bac8 | 2006-10-09 17:36:45 +0000 | [diff] [blame] | 70 | <h2>$this->load->library('<var>class_name</var>')</h2>
|
| 71 |
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 72 | <p>This function is used to load core classes. Where <var>class_name</var> is the name of the class you want to load.
|
admin | 2f0bac8 | 2006-10-09 17:36:45 +0000 | [diff] [blame] | 73 | Note: We use the terms "class" and "library" interchangeably.</p>
|
| 74 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 75 | <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>
|
admin | 2f0bac8 | 2006-10-09 17:36:45 +0000 | [diff] [blame] | 76 |
|
| 77 | <code>$this->load->library('email');</code>
|
| 78 |
|
| 79 | <p>Once loaded, the library will be ready for use, using <kbd>$this->email-></kbd><samp><em>some_function</em>()</samp>.
|
| 80 |
|
admin | e7e1dcd | 2006-10-21 18:04:01 +0000 | [diff] [blame] | 81 | Each library is described in detail in its own page, so please read the information regarding each one you would like to use.</p>
|
admin | 2f0bac8 | 2006-10-09 17:36:45 +0000 | [diff] [blame] | 82 |
|
Derek Allard | c644128 | 2007-07-04 23:54:32 +0000 | [diff] [blame] | 83 | <p>Parameters can be passed to the library via an array in the second parameter.</p>
|
admin | cf49390 | 2006-10-10 07:12:31 +0000 | [diff] [blame] | 84 |
|
| 85 |
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 86 | <h2>$this->load->view('<var>file_name</var>', <samp>$data</samp>, <kbd>true/false</kbd>)</h2>
|
| 87 |
|
| 88 | <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
|
| 89 | user guide it is recommended that you do since it shows you how this function is typically used.</p>
|
| 90 |
|
admin | 1b90c27 | 2006-10-31 18:22:29 +0000 | [diff] [blame] | 91 | <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 then <kbd>.php</kbd>.</p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 92 |
|
| 93 | <p>The second <strong>optional</strong> parameter can take
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 94 | 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
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 95 | convert to variables that can be used in your view files. Again, read the <a href="../general/views.html">Views</a> page to learn
|
| 96 | how this might be useful.</p>
|
| 97 |
|
| 98 | <p>The third <strong>optional</strong> parameter lets you change the behavior of the function so that it returns data as a string
|
| 99 | rather than sending it to your browser. This can be useful if you want to process the data in some way. If you
|
| 100 | set the parameter to <kbd>true</kbd> (boolean) it will return data. The default behavior is <kbd>false</kbd>, which sends it
|
Derek Allard | d8b92a3 | 2007-03-28 01:26:32 +0000 | [diff] [blame] | 101 | to your browser. Remember to assign it to a variable if you want the data returned:</p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 102 |
|
| 103 | <code>$string = $this->load->view('<var>myfile</var>', '', <kbd>true</kbd>);</code>
|
| 104 |
|
| 105 |
|
Derek Allard | c8b2174 | 2008-05-18 03:57:40 +0000 | [diff] [blame] | 106 | <h2>$this->load->model('<var>Model_name</var>');</h2>
|
| 107 | <p><code>$this->load->model('<var>Model_name</var>');</code></p>
|
Derek Allard | 6d504e1 | 2008-05-26 02:34:43 +0000 | [diff] [blame] | 108 | <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>
|
Derek Allard | c8b2174 | 2008-05-18 03:57:40 +0000 | [diff] [blame] | 109 | <p><code>$this->load->model('<var>blog/queries</var>');</code></p>
|
| 110 | <p>If you would like your model assigned to a different object name you can specify it via the second parameter of the loading
|
| 111 | function:</p>
|
| 112 | <code> $this->load->model('<var>Model_name</var>', '<kbd>fubar</kbd>');<br />
|
| 113 | <br />
|
| 114 | $this-><kbd>fubar</kbd>->function();</code>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 115 | <h2>$this->load->database('<var>options</var>', <kbd>true/false</kbd>)</h2>
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 116 | <p>This function lets you load the database class. The two parameters are <strong>optional</strong>. Please see the
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 117 | <a href="./database/index.html">database</a> section for more info.</p>
|
| 118 |
|
| 119 |
|
| 120 | <h2>$this->load->scaffolding('<var>table_name</var>')</h2>
|
| 121 |
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 122 | <p>This function lets you enable scaffolding. Please see the
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 123 | <a href="../general/scaffolding.html">scaffolding</a> section for more info.</p>
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 | <h2>$this->load->vars(<samp>$array</samp>)</h2>
|
| 128 |
|
| 129 | <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.
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 130 | This function produces the same result as using the second parameter of the <dfn>$this->load->view()</dfn> function above. The reason you might
|
| 131 | want to use this function independently is if you would like to set some global variables in the constructor of your controller
|
| 132 | 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
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 133 | and merged into one array for conversion to variables.
|
| 134 | </p>
|
| 135 |
|
| 136 |
|
| 137 | <h2>$this->load->helper('<var>file_name</var>')</h2>
|
| 138 | <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>
|
| 139 |
|
| 140 |
|
| 141 | <h2>$this->load->plugin('<var>file_name</var>')</h2>
|
| 142 | <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>
|
| 143 |
|
| 144 | <h2>$this->load->file('<var>filepath/filename</var>', <kbd>true/false</kbd>)</h2>
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 145 | <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.
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 146 | 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)
|
| 147 | it will instead return the data as a string.</p>
|
| 148 |
|
| 149 |
|
Derek Jones | fd93d22 | 2008-05-06 15:18:50 +0000 | [diff] [blame] | 150 | <h2>$this->load->lang('<var>file_name</var>')</h2>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 151 | <p>This function is an alias of the <a href="language.html">language loading function</a>: $this->lang->load()</p>
|
| 152 |
|
| 153 | <h2>$this->load->config('<var>file_name</var>')</h2>
|
| 154 | <p>This function is an alias of the <a href="config.html">config file loading function</a>: $this->config->load()</p>
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 | </div>
|
| 160 | <!-- END CONTENT -->
|
| 161 |
|
| 162 |
|
| 163 | <div id="footer">
|
| 164 | <p>
|
| 165 | Previous Topic: <a href="input.html">Input Class</a>
|
| 166 | ·
|
| 167 | <a href="#top">Top of Page</a> ·
|
| 168 | <a href="../index.html">User Guide Home</a> ·
|
| 169 | Next Topic: <a href="language.html">Language Class</a>
|
Derek Allard | c644128 | 2007-07-04 23:54:32 +0000 | [diff] [blame] | 170 | </p>
|
Derek Jones | 0787043 | 2008-02-13 03:49:26 +0000 | [diff] [blame] | 171 | <p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 172 | </div>
|
| 173 |
|
| 174 | </body>
|
| 175 | </html> |