| 1 |
lars |
1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
2 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
|
3 |
<head>
|
|
|
4 |
|
|
|
5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
6 |
<title>HTML Helper : CodeIgniter User Guide</title>
|
|
|
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 |
|
|
|
11 |
<script type="text/javascript" src="../nav/nav.js"></script>
|
|
|
12 |
<script type="text/javascript" src="../nav/prototype.lite.js"></script>
|
|
|
13 |
<script type="text/javascript" src="../nav/moo.fx.js"></script>
|
|
|
14 |
<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
|
|
|
15 |
|
|
|
16 |
<meta http-equiv='expires' content='-1' />
|
|
|
17 |
<meta http-equiv= 'pragma' content='no-cache' />
|
|
|
18 |
<meta name='robots' content='all' />
|
|
|
19 |
<meta name='author' content='ExpressionEngine Dev Team' />
|
|
|
20 |
<meta name='description' content='CodeIgniter User Guide' />
|
|
|
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_darker.jpg" width="154" height="43" 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>
|
|
|
31 |
<td><h1>CodeIgniter User Guide Version 1.7.1</h1></td>
|
|
|
32 |
<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
|
|
|
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">
|
|
|
43 |
<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
|
|
|
44 |
<a href="../index.html">User Guide Home</a> ›
|
|
|
45 |
HTML Helper
|
|
|
46 |
</td>
|
|
|
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>
|
|
|
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>HTML Helper</h1>
|
|
|
60 |
|
|
|
61 |
<p>The HTML Helper file contains functions that assist in working with HTML.</p>
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
<h2>Loading this Helper</h2>
|
|
|
65 |
|
|
|
66 |
<p>This helper is loaded using the following code:</p>
|
|
|
67 |
<code>$this->load->helper('html');</code>
|
|
|
68 |
|
|
|
69 |
<p>The following functions are available:</p>
|
|
|
70 |
|
|
|
71 |
<h2>br()</h2>
|
|
|
72 |
<p>Generates line break tags (<br />) based on the number you submit. Example:</p>
|
|
|
73 |
<code>echo br(3);</code>
|
|
|
74 |
<p>The above would produce: <br /><br /><br /></p>
|
|
|
75 |
|
|
|
76 |
<h2>heading()</h2>
|
|
|
77 |
<p>Lets you create HTML <h1> tags. The first parameter will contain the data, the
|
|
|
78 |
second the size of the heading. Example:</p>
|
|
|
79 |
<code>echo heading('Welcome!', 3);</code>
|
|
|
80 |
<p>The above would produce: <h3>Welcome!</h3></p>
|
|
|
81 |
<h2>img()</h2>
|
|
|
82 |
<p>Lets you create HTML <img /> tags. The first parameter contains the image source. Example:</p>
|
|
|
83 |
<code>echo img('images/picture.jpg');<br />
|
|
|
84 |
// gives <img src="http://site.com/images/picture.jpg" /></code>
|
|
|
85 |
<p>There is an optional second parameter that is a TRUE/FALSE value that specifics if the src should have the page specified by $config['index_page'] added to the address it creates. Presumably, this would be if you were using a media controller.</p>
|
|
|
86 |
<p><code>echo img('images/picture.jpg', TRUE);<br />
|
|
|
87 |
// gives <img src="http://site.com/index.php/images/picture.jpg" /></code></p>
|
|
|
88 |
<p>Additionally, an associative array can be passed to the img() function for complete control over all attributes and values.</p>
|
|
|
89 |
<p><code> $image_properties = array(<br />
|
|
|
90 |
'src' => 'images/picture.jpg',<br />
|
|
|
91 |
'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time',<br />
|
|
|
92 |
'class' => 'post_images',<br />
|
|
|
93 |
'width' => '200',<br />
|
|
|
94 |
'height' => '200',<br />
|
|
|
95 |
'title' => 'That was quite a night',<br />
|
|
|
96 |
'rel' => 'lightbox',<br />
|
|
|
97 |
);<br />
|
|
|
98 |
<br />
|
|
|
99 |
img($image_properties);<br />
|
|
|
100 |
// <img src="http://site.com/index.php/images/picture.jpg" alt="Me, demonstrating how to eat 4 slices of pizza at one time" class="post_images" width="200" height="200" title="That was quite a night" rel="lightbox" /></code></p>
|
|
|
101 |
<h2>link_tag()</h2>
|
|
|
102 |
<p>Lets you create HTML <link /> tags. This is useful for stylesheet links, as well as other links. The parameters are href, with optional rel, type, title, media and index_page. index_page is a TRUE/FALSE value that specifics if the href should have the page specified by $config['index_page'] added to the address it creates.<code>
|
|
|
103 |
echo link_tag('css/mystyles.css');<br />
|
|
|
104 |
// gives <link href="http://site.com/css/mystyles.css" rel="stylesheet" type="text/css" /></code></p>
|
|
|
105 |
<p>Further examples:</p>
|
|
|
106 |
|
|
|
107 |
<code>
|
|
|
108 |
echo link_tag('favicon.ico', 'shortcut icon', 'image/ico');<br />
|
|
|
109 |
// <link href="http://site.com/favicon.ico" rel="shortcut icon" type="image/ico" />
|
|
|
110 |
<br />
|
|
|
111 |
<br />
|
|
|
112 |
echo link_tag('feed', 'alternate', 'application/rss+xml', 'My RSS Feed');<br />
|
|
|
113 |
// <link href="http://site.com/feed" rel="alternate" type="application/rss+xml" title="My RSS Feed" /> </code>
|
|
|
114 |
<p>Additionally, an associative array can be passed to the link() function for complete control over all attributes and values.</p>
|
|
|
115 |
<p><code>
|
|
|
116 |
$link = array(<br />
|
|
|
117 |
'href' => 'css/printer.css',<br />
|
|
|
118 |
'rel' => 'stylesheet',<br />
|
|
|
119 |
'type' => 'text/css',<br />
|
|
|
120 |
'media' => 'print'<br />
|
|
|
121 |
);<br />
|
|
|
122 |
<br />
|
|
|
123 |
echo link_tag($link);<br />
|
|
|
124 |
// <link href="http://site.com/css/printer.css" rel="stylesheet" type="text/css" media="print" /></code></p>
|
|
|
125 |
|
|
|
126 |
<h2>nbs()</h2>
|
|
|
127 |
<p>Generates non-breaking spaces (&nbsp;) based on the number you submit. Example:</p>
|
|
|
128 |
<code>echo nbs(3);</code>
|
|
|
129 |
<p>The above would produce: &nbsp;&nbsp;&nbsp;</p>
|
|
|
130 |
|
|
|
131 |
<h2>ol() and ul()</h2>
|
|
|
132 |
|
|
|
133 |
<p>Permits you to generate ordered or unordered HTML lists from simple or multi-dimensional arrays. Example:</p>
|
|
|
134 |
|
|
|
135 |
<code>
|
|
|
136 |
$this->load->helper('html');<br />
|
|
|
137 |
<br />
|
|
|
138 |
$list = array(<br />
|
|
|
139 |
'red', <br />
|
|
|
140 |
'blue', <br />
|
|
|
141 |
'green',<br />
|
|
|
142 |
'yellow'<br />
|
|
|
143 |
);<br />
|
|
|
144 |
<br />
|
|
|
145 |
$attributes = array(<br />
|
|
|
146 |
'class' => 'boldlist',<br />
|
|
|
147 |
'id' => 'mylist'<br />
|
|
|
148 |
);<br />
|
|
|
149 |
<br />
|
|
|
150 |
echo ul($list, $attributes);<br />
|
|
|
151 |
</code>
|
|
|
152 |
|
|
|
153 |
<p>The above code will produce this:</p>
|
|
|
154 |
|
|
|
155 |
<code>
|
|
|
156 |
<ul class="boldlist" id="mylist"><br />
|
|
|
157 |
<li>red</li><br />
|
|
|
158 |
<li>blue</li><br />
|
|
|
159 |
<li>green</li><br />
|
|
|
160 |
<li>yellow</li><br />
|
|
|
161 |
</ul>
|
|
|
162 |
</code>
|
|
|
163 |
|
|
|
164 |
<p>Here is a more complex example, using a multi-dimensional array:</p>
|
|
|
165 |
|
|
|
166 |
<code>
|
|
|
167 |
$this->load->helper('html');<br />
|
|
|
168 |
<br />
|
|
|
169 |
$attributes = array(<br />
|
|
|
170 |
'class' => 'boldlist',<br />
|
|
|
171 |
'id' => 'mylist'<br />
|
|
|
172 |
);<br />
|
|
|
173 |
<br />
|
|
|
174 |
$list = array(<br />
|
|
|
175 |
'colors' => array(<br />
|
|
|
176 |
'red',<br />
|
|
|
177 |
'blue',<br />
|
|
|
178 |
'green'<br />
|
|
|
179 |
),<br />
|
|
|
180 |
'shapes' => array(<br />
|
|
|
181 |
'round', <br />
|
|
|
182 |
'square',<br />
|
|
|
183 |
'circles' => array(<br />
|
|
|
184 |
'ellipse', <br />
|
|
|
185 |
'oval', <br />
|
|
|
186 |
'sphere'<br />
|
|
|
187 |
)<br />
|
|
|
188 |
),<br />
|
|
|
189 |
'moods' => array(<br />
|
|
|
190 |
'happy', <br />
|
|
|
191 |
'upset' => array(<br />
|
|
|
192 |
'defeated' => array(<br />
|
|
|
193 |
'dejected',<br />
|
|
|
194 |
'disheartened',<br />
|
|
|
195 |
'depressed'<br />
|
|
|
196 |
),<br />
|
|
|
197 |
'annoyed',<br />
|
|
|
198 |
'cross',<br />
|
|
|
199 |
'angry'<br />
|
|
|
200 |
)<br />
|
|
|
201 |
)<br />
|
|
|
202 |
);<br />
|
|
|
203 |
<br />
|
|
|
204 |
<br />
|
|
|
205 |
echo ul($list, $attributes);</code>
|
|
|
206 |
|
|
|
207 |
<p>The above code will produce this:</p>
|
|
|
208 |
|
|
|
209 |
<code>
|
|
|
210 |
<ul class="boldlist" id="mylist"><br />
|
|
|
211 |
<li>colors<br />
|
|
|
212 |
<ul><br />
|
|
|
213 |
<li>red</li><br />
|
|
|
214 |
<li>blue</li><br />
|
|
|
215 |
<li>green</li><br />
|
|
|
216 |
</ul><br />
|
|
|
217 |
</li><br />
|
|
|
218 |
<li>shapes<br />
|
|
|
219 |
<ul><br />
|
|
|
220 |
<li>round</li><br />
|
|
|
221 |
<li>suare</li><br />
|
|
|
222 |
<li>circles<br />
|
|
|
223 |
<ul><br />
|
|
|
224 |
<li>elipse</li><br />
|
|
|
225 |
<li>oval</li><br />
|
|
|
226 |
<li>sphere</li><br />
|
|
|
227 |
</ul><br />
|
|
|
228 |
</li><br />
|
|
|
229 |
</ul><br />
|
|
|
230 |
</li><br />
|
|
|
231 |
<li>moods<br />
|
|
|
232 |
<ul><br />
|
|
|
233 |
<li>happy</li><br />
|
|
|
234 |
<li>upset<br />
|
|
|
235 |
<ul><br />
|
|
|
236 |
<li>defeated<br />
|
|
|
237 |
<ul><br />
|
|
|
238 |
<li>dejected</li><br />
|
|
|
239 |
<li>disheartened</li><br />
|
|
|
240 |
<li>depressed</li><br />
|
|
|
241 |
</ul><br />
|
|
|
242 |
</li><br />
|
|
|
243 |
<li>annoyed</li><br />
|
|
|
244 |
<li>cross</li><br />
|
|
|
245 |
<li>angry</li><br />
|
|
|
246 |
</ul><br />
|
|
|
247 |
</li><br />
|
|
|
248 |
</ul><br />
|
|
|
249 |
</li><br />
|
|
|
250 |
</ul>
|
|
|
251 |
</code>
|
|
|
252 |
|
|
|
253 |
|
|
|
254 |
|
|
|
255 |
<h2>meta()</h2>
|
|
|
256 |
|
|
|
257 |
<p>Helps you generate meta tags. You can pass strings to the function, or simple arrays, or multidimensional ones. Examples:</p>
|
|
|
258 |
|
|
|
259 |
<code>
|
|
|
260 |
echo meta('description', 'My Great site');<br />
|
|
|
261 |
// Generates: <meta name="description" content="My Great Site" /><br />
|
|
|
262 |
<br /><br />
|
|
|
263 |
|
|
|
264 |
echo meta('Content-type', 'text/html; charset=utf-8', 'equiv'); // Note the third parameter. Can be "equiv" or "name"<br />
|
|
|
265 |
// Generates: <meta http-equiv="Content-type" content="text/html; charset=utf-8" /><br />
|
|
|
266 |
|
|
|
267 |
<br /><br />
|
|
|
268 |
|
|
|
269 |
echo meta(array('name' => 'robots', 'content' => 'no-cache'));<br />
|
|
|
270 |
// Generates: <meta name="robots" content="no-cache" /><br />
|
|
|
271 |
|
|
|
272 |
<br /><br />
|
|
|
273 |
|
|
|
274 |
$meta = array(<br />
|
|
|
275 |
array('name' => 'robots', 'content' => 'no-cache'),<br />
|
|
|
276 |
array('name' => 'description', 'content' => 'My Great Site'),<br />
|
|
|
277 |
array('name' => 'keywords', 'content' => 'love, passion, intrigue, deception'),<br />
|
|
|
278 |
array('name' => 'robots', 'content' => 'no-cache'),<br />
|
|
|
279 |
array('name' => 'Content-type', 'content' => 'text/html; charset=utf-8', 'type' => 'equiv')<br />
|
|
|
280 |
);<br />
|
|
|
281 |
<br />
|
|
|
282 |
echo meta($meta);
|
|
|
283 |
<br />
|
|
|
284 |
// Generates: <br />
|
|
|
285 |
// <meta name="robots" content="no-cache" /><br />
|
|
|
286 |
// <meta name="description" content="My Great Site" /><br />
|
|
|
287 |
// <meta name="keywords" content="love, passion, intrigue, deception" /><br />
|
|
|
288 |
// <meta name="robots" content="no-cache" /><br />
|
|
|
289 |
// <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
|
|
|
290 |
</code>
|
|
|
291 |
|
|
|
292 |
|
|
|
293 |
<h2>doctype()</h2>
|
|
|
294 |
|
|
|
295 |
<p>Helps you generate document type declarations, or DTD's. XHTML 1.0 Strict is used by default, but many doctypes are available.</p>
|
|
|
296 |
|
|
|
297 |
<code>
|
|
|
298 |
echo docytype();<br />
|
|
|
299 |
// <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><br />
|
|
|
300 |
<br />
|
|
|
301 |
echo doctype('html4-trans');<br />
|
|
|
302 |
// <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
|
303 |
</code>
|
|
|
304 |
|
|
|
305 |
<p>The following is a list of doctype choices. These are configurable, and pulled from <samp>application/config/doctypes.php</samp></p>
|
|
|
306 |
|
|
|
307 |
<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
|
|
|
308 |
<tr>
|
|
|
309 |
<th>Doctype</th>
|
|
|
310 |
<th>Option</th>
|
|
|
311 |
<th>Result</th>
|
|
|
312 |
</tr>
|
|
|
313 |
<tr>
|
|
|
314 |
<td class="td">XHTML 1.1</td>
|
|
|
315 |
<td class="td">doctype('xhtml11')</td>
|
|
|
316 |
<td class="td"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"></td>
|
|
|
317 |
</tr>
|
|
|
318 |
<tr>
|
|
|
319 |
<td class="td">XHTML 1.0 Strict</td>
|
|
|
320 |
<td class="td">doctype('xhtml1-strict')</td>
|
|
|
321 |
<td class="td"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"></td>
|
|
|
322 |
</tr>
|
|
|
323 |
<tr>
|
|
|
324 |
<td class="td">XHTML 1.0 Transitional</td>
|
|
|
325 |
<td class="td">doctype('xhtml1-trans')</td>
|
|
|
326 |
<td class="td"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></td>
|
|
|
327 |
</tr>
|
|
|
328 |
<tr>
|
|
|
329 |
<td class="td">XHTML 1.0 Frameset</td>
|
|
|
330 |
<td class="td">doctype('xhtml1-frame')</td>
|
|
|
331 |
<td class="td"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"></td>
|
|
|
332 |
</tr>
|
|
|
333 |
<tr>
|
|
|
334 |
<td class="td">HTML 5</td>
|
|
|
335 |
<td class="td">doctype('html5')</td>
|
|
|
336 |
<td class="td"><!DOCTYPE html></td>
|
|
|
337 |
</tr>
|
|
|
338 |
<tr>
|
|
|
339 |
<td class="td">HTML 4 Strict</td>
|
|
|
340 |
<td class="td">doctype('html4-strict')</td>
|
|
|
341 |
<td class="td"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"></td>
|
|
|
342 |
</tr>
|
|
|
343 |
<tr>
|
|
|
344 |
<td class="td">HTML 4 Transitional</td>
|
|
|
345 |
<td class="td">doctype('html4-trans')</td>
|
|
|
346 |
<td class="td"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"></td>
|
|
|
347 |
</tr>
|
|
|
348 |
<tr>
|
|
|
349 |
<td class="td">HTML 4 Frameset</td>
|
|
|
350 |
<td class="td">doctype('html4-frame')</td>
|
|
|
351 |
<td class="td"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"></td>
|
|
|
352 |
</tr>
|
|
|
353 |
</table>
|
|
|
354 |
|
|
|
355 |
|
|
|
356 |
|
|
|
357 |
|
|
|
358 |
</div>
|
|
|
359 |
<!-- END CONTENT -->
|
|
|
360 |
|
|
|
361 |
|
|
|
362 |
<div id="footer">
|
|
|
363 |
<p>
|
|
|
364 |
Previous Topic: <a href="form_helper.html">Form Helper</a>
|
|
|
365 |
·
|
|
|
366 |
<a href="#top">Top of Page</a> ·
|
|
|
367 |
<a href="../index.html">User Guide Home</a> ·
|
|
|
368 |
Next Topic: <a href="path_helper.html"> Path Helper</a></p>
|
|
|
369 |
<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
|
|
|
370 |
</div>
|
|
|
371 |
|
|
|
372 |
</body>
|
|
|
373 |
</html>
|