admin | 9fd91c0 | 2006-10-09 03:30:36 +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 |
|
| 10 | <script type="text/javascript" src="../nav/nav.js"></script>
|
| 11 | <script type="text/javascript" src="../nav/prototype.lite.js"></script>
|
| 12 | <script type="text/javascript" src="../nav/moo.fx.js"></script>
|
| 13 | <script type="text/javascript">
|
| 14 | window.onload = function() {
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 15 | myHeight = new fx.Height('nav', {duration: 400});
|
admin | 9fd91c0 | 2006-10-09 03:30:36 +0000 | [diff] [blame] | 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 | e0cd609 | 2006-10-20 01:00:31 +0000 | [diff] [blame] | 36 | <td><h1>Code Igniter User Guide Version 1.5.0b3</h1></td>
|
admin | 4979a12 | 2006-10-11 19:40:07 +0000 | [diff] [blame] | 37 | <td id="breadcrumb_right"><a href="../toc.html">Linear Table of Contents</a></td>
|
admin | 9fd91c0 | 2006-10-09 03:30:36 +0000 | [diff] [blame] | 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> ›
|
admin | a396276 | 2006-10-09 03:31:32 +0000 | [diff] [blame] | 50 | HTML Table Class
|
admin | 9fd91c0 | 2006-10-09 03:30:36 +0000 | [diff] [blame] | 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 |
|
admin | a396276 | 2006-10-09 03:31:32 +0000 | [diff] [blame] | 64 | <h1>HTML Table Class</h1>
|
admin | 9fd91c0 | 2006-10-09 03:30:36 +0000 | [diff] [blame] | 65 |
|
admin | a396276 | 2006-10-09 03:31:32 +0000 | [diff] [blame] | 66 | <p>The Table Class provides functions that enable you to auto-generate HTML tables from arrays or database result sets.</p>
|
admin | 9fd91c0 | 2006-10-09 03:30:36 +0000 | [diff] [blame] | 67 |
|
| 68 | <h2>Initializing the Class</h2>
|
| 69 |
|
admin | a396276 | 2006-10-09 03:31:32 +0000 | [diff] [blame] | 70 | <p>Like most other classes in Code Igniter, the Table class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
|
admin | 9fd91c0 | 2006-10-09 03:30:36 +0000 | [diff] [blame] | 71 |
|
admin | a396276 | 2006-10-09 03:31:32 +0000 | [diff] [blame] | 72 | <code>$this->load->library('table');</code>
|
admin | a1931ad | 2006-10-09 04:17:38 +0000 | [diff] [blame] | 73 | <p>Once loaded, the Table library object will be available using: <dfn>$this->table</dfn></p>
|
admin | 9fd91c0 | 2006-10-09 03:30:36 +0000 | [diff] [blame] | 74 |
|
| 75 |
|
admin | a1931ad | 2006-10-09 04:17:38 +0000 | [diff] [blame] | 76 | <h2>Examples</h2>
|
| 77 |
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 78 | <p>Here is an example showing how you can create a table from a multi-dimensional array.
|
| 79 | Note that the first array index will become the table heading (or you can set your own headings using the
|
admin | 2f0bac8 | 2006-10-09 17:36:45 +0000 | [diff] [blame] | 80 | <dfn>set_heading()</dfn> function described in the function reference below).</p>
|
admin | a1931ad | 2006-10-09 04:17:38 +0000 | [diff] [blame] | 81 |
|
| 82 | <code>
|
| 83 | $this->load->library('table');<br />
|
| 84 | <br />
|
| 85 | $data = array(<br />
|
| 86 | array('Name', 'Color', 'Size'),<br />
|
| 87 | array('Fred', 'Blue', 'Small'),<br />
|
| 88 | array('Mary', 'Red', 'Large'),<br />
|
| 89 | array('John', 'Green', 'Medium') <br />
|
| 90 | );<br />
|
| 91 | <br />
|
| 92 | echo $this->table->generate($data);
|
| 93 | </code>
|
| 94 |
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 95 | <p>Here is an example of a table created from a database query result. The table class will automatically generate the
|
admin | 2f0bac8 | 2006-10-09 17:36:45 +0000 | [diff] [blame] | 96 | headings based on the table names (or you can set your own headings using the <dfn>set_heading()</dfn> function described
|
| 97 | in the function reference below).</p>
|
admin | a1931ad | 2006-10-09 04:17:38 +0000 | [diff] [blame] | 98 |
|
| 99 | <code>
|
| 100 | $this->load->library('table');<br />
|
| 101 | <br />
|
| 102 | $query = $this->db->query("SELECT * FROM my_table");<br />
|
| 103 | <br />
|
| 104 | echo $this->table->generate($query);
|
| 105 | </code>
|
| 106 |
|
| 107 |
|
| 108 | <p>Here is an example showing how you might create a table using discreet parameters:</p>
|
| 109 |
|
| 110 | <code>
|
| 111 | $this->load->library('table');<br />
|
| 112 | <br />
|
| 113 | $this->table->set_heading('Name', 'Color', 'Size');<br />
|
| 114 | <br />
|
| 115 | $this->table->add_row('Fred', 'Blue', 'Small');<br />
|
| 116 | $this->table->add_row('Mary', 'Red', 'Large');<br />
|
| 117 | $this->table->add_row('John', 'Green', 'Medium');<br />
|
| 118 | <br />
|
| 119 | echo $this->table->generate();
|
| 120 | </code>
|
| 121 |
|
| 122 | <p>Here is the same example, except instead of individual parameters, arrays are used:
|
| 123 |
|
| 124 | <code>
|
| 125 | $this->load->library('table');<br />
|
| 126 | <br />
|
| 127 | $this->table->set_heading(array('Name', 'Color', 'Size'));<br />
|
| 128 | <br />
|
| 129 | $this->table->add_row(array('Fred', 'Blue', 'Small'));<br />
|
| 130 | $this->table->add_row(array('Mary', 'Red', 'Large'));<br />
|
| 131 | $this->table->add_row(array('John', 'Green', 'Medium'));<br />
|
| 132 | <br />
|
| 133 | echo $this->table->generate();
|
| 134 | </code>
|
| 135 |
|
| 136 |
|
| 137 | <h2>Changing the Look of Your Table</h2>
|
| 138 |
|
| 139 | <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
|
| 140 | prototype:</p>
|
| 141 |
|
| 142 | <code>
|
| 143 | $tmpl = array (<br />
|
| 144 | 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',<br />
|
| 145 | <br />
|
| 146 | 'heading_row_start' => '<tr>',<br />
|
| 147 | 'heading_row_end' => '</tr>',<br />
|
| 148 | 'heading_cell_start' => '<th>',<br />
|
| 149 | 'heading_cell_end' => '</th>',<br />
|
| 150 | <br />
|
| 151 | 'row_start' => '<tr>',<br />
|
| 152 | 'row_end' => '</tr>',<br />
|
| 153 | 'cell_start' => '<td>',<br />
|
| 154 | 'cell_end' => '</td>',<br />
|
| 155 | <br />
|
| 156 | 'row_alt_start' => '<tr>',<br />
|
| 157 | 'row_alt_end' => '</tr>',<br />
|
| 158 | 'cell_alt_start' => '<td>',<br />
|
| 159 | 'cell_alt_end' => '</td>',<br />
|
| 160 | <br />
|
| 161 | 'table_close' => '</table>'<br />
|
| 162 | );<br />
|
| 163 |
|
| 164 | <br />
|
| 165 | $this->table->set_template($tmpl);
|
| 166 | </code>
|
| 167 |
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 168 | <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
|
admin | a1931ad | 2006-10-09 04:17:38 +0000 | [diff] [blame] | 169 | iteration of the row data.</p>
|
| 170 |
|
| 171 | <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.
|
| 172 | In this example, only the table opening tag is being changed:</p>
|
| 173 |
|
| 174 | <code>
|
| 175 | $tmpl = array ( 'table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' );<br />
|
| 176 |
|
| 177 | <br />
|
| 178 | $this->table->set_template($tmpl);
|
| 179 | </code>
|
| 180 |
|
| 181 | <br />
|
| 182 | <h1>Function Reference</h1>
|
| 183 |
|
| 184 | <h2>$this->table->generate()</h2>
|
| 185 | <p>Returns a string containing the generated table. Accepts an optional parameter which can be an array or a database result object.</p>
|
| 186 |
|
| 187 | <h2>$this->table->set_heading()</h2>
|
| 188 |
|
| 189 | <p>Permits you to set the table heading. You can submit an array or discreet params:</p>
|
| 190 |
|
| 191 | <code>$this->table->set_heading('Name', 'Color', 'Size');</code>
|
| 192 | <code>$this->table->set_heading(array('Name', 'Color', 'Size'));</code>
|
| 193 |
|
| 194 | <h2>$this->table->add_row()</h2>
|
| 195 |
|
| 196 | <p>Permits you to add a row to your table. You can submit an array or discreet params:</p>
|
| 197 |
|
| 198 | <code>$this->table->add_row('Blue', 'Red', 'Green');</code>
|
| 199 | <code>$this->table->add_row(array('Blue', 'Red', 'Green'));</code>
|
| 200 |
|
| 201 | <h2>$this->table->set_template()</h2>
|
| 202 |
|
| 203 | <p>Permits you to set your template. You can submit a full or partial template.</p>
|
| 204 |
|
| 205 | <code>
|
| 206 | $tmpl = array ( 'table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' );<br />
|
| 207 |
|
| 208 | <br />
|
| 209 | $this->table->set_template($tmpl);
|
| 210 | </code>
|
admin | 9fd91c0 | 2006-10-09 03:30:36 +0000 | [diff] [blame] | 211 |
|
| 212 |
|
| 213 | </div>
|
| 214 | <!-- END CONTENT -->
|
| 215 |
|
| 216 |
|
| 217 | <div id="footer">
|
| 218 | <p>
|
admin | 4003718 | 2006-10-11 19:16:58 +0000 | [diff] [blame] | 219 | Previous Topic: <a href="file_uploading.html">File Uploading Class</a>
|
admin | 9fd91c0 | 2006-10-09 03:30:36 +0000 | [diff] [blame] | 220 | ·
|
| 221 | <a href="#top">Top of Page</a> ·
|
| 222 | <a href="../index.html">User Guide Home</a> ·
|
admin | 4003718 | 2006-10-11 19:16:58 +0000 | [diff] [blame] | 223 | Next Topic: <a href="image_lib.html">Image Manipulation Class</a>
|
admin | 9fd91c0 | 2006-10-09 03:30:36 +0000 | [diff] [blame] | 224 | <p>
|
| 225 | <p><a href="http://www.codeigniter.com">Code Igniter</a> · Copyright © 2006 · <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
|
| 226 | </div>
|
| 227 |
|
| 228 | </body>
|
| 229 | </html> |