blob: c173f5690e2e4e19fa849eef0606de16f071df40 [file] [log] [blame]
adminb0dd10f2006-08-25 17:25:49 +00001<!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
10<script type="text/javascript" src="../scripts/nav.js"></script>
11<script type="text/javascript" src="../scripts/prototype.lite.js"></script>
12<script type="text/javascript" src="../scripts/moo.fx.js"></script>
13<script type="text/javascript">
14window.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>
36<td><h1>Code Igniter User Guide Version 1.4.0</h1></td>
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> &nbsp;&#8250;&nbsp;
49<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
50Config 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&nbsp; <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />&nbsp;<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>Config Class</h1>
65
66<p>The Config class provides a means to retrieve configuration preferences. These preferences can
67come from the default config file (<samp>application/config/config.php</samp>) or from your own custom config 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
72<h2>Anatomy of a Config File</h2>
73
74<p>By default, Code Igniter has a one primary config file, located at <samp>application/config/config.php</samp>. If you open the file using
75your text editor you'll see that config items are stored in an array called <var>$config</var>.</p>
76
77<p>You can add your own config items to
78this file, or if you prefer to keep your configuration items separate (assuming you even need config items),
79simply create your own file and save it in <dfn>config</dfn> folder.</p>
80
81<p><strong>Note:</strong> If you do create your own config files use the same format as the primary one, storing your items in
82an array called <var>$config</var>. Code Igniter will intelligently manage these files so there will be no conflict even though
83the array has the same name (assuming an array index is not named the same as another).</p>
84
85<h2>Loading a Config File</h2>
86
87<p><strong>Note:</strong> Code Igniter automatically loads the primary config file (<samp>application/config/config.php</samp>),
88so you will only need to load a config file if you have created your own.</p>
89
90<p>There are two ways to load a config file:</p>
91
92<ol><li><strong>Manual Loading</strong>
93
94<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>
95
96<code>$this->config->load('<var>filename</var>');</code>
97
98<p>Where <var>filename</var> is the name of your config file, without the .php file extension.</p>
99
100</li>
101<li><strong>Auto-loading</strong></li>
102
103<p>If you find that you need a particular config file globally, you can have it loaded automatically by the system. To do this,
104open the <strong>autoload.php</strong> file, located at <samp>application/config/autoload.php</samp>, and add your config file as
105indicated in the file.</p>
106</li>
107</ol>
108
109
110<h2>Fetching Config Items</h2>
111
112<p>To retrive an item from your config file, use the following function:</p>
113
114<code>$this->config->item('<var>item name</var>');</code>
115
116<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>
117
118<code>$lang = $this->config->item('language');</code>
119
120<p>The function returns FALSE (boolean) if the item you are trying to fetch does not exist.</p>
121
122<h2>Setting a Config Item</h2>
123
124<p>If you would like to dynamically set a config item or change an existing one, you can so so using:</p>
125
126<code>$this->config->set_item('<var>item_name</var>', '<var>item_value</var>');</code>
127
128<p>Where <var>item_name</var> is the $config array index you want to change, and <var>item_value</var> is its value.</p>
129
130
131<h2>Helper Functions</h2>
132
133<p>The config class has the following helper functions:</p>
134
135<h2>$this->config->site_url();</h2>
136<p>This function retrieves the URL to your site, along with the "index" value you've specified in the config file.</p>
137
138<h2>$this->config->system_url();</h2>
139<p>This function retrieves the URL to your <dfn>system folder</dfn>.</p>
140
141
142</div>
143<!-- END CONTENT -->
144
145
146<div id="footer">
147<p>
148Previous Topic:&nbsp;&nbsp;<a href="calendar.html">Calendaring Class</a>
149&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
150<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
151<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
152Next Topic:&nbsp;&nbsp;<a href="database/index.html">Database Class</a>
153<p>
154<p><a href="http://www.codeigniter.com">Code Igniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2006 &nbsp;&middot;&nbsp; <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
155</div>
156
157</body>
158</html>