carbonPHP Initial commit v2.0
[carbonphp.git] / Documentation / libraries / table.html
blobc718d1ea292f2f9bb9efd949d48b498ea51dab66
1 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
2 <head>
3 <title>CarbonPHP Documentation</title>
4 <style type="text/css">
5 * {
6 margin: 0;
7 padding: 0;
10 html {
11 font-family: "Lucida Sans Unicode", "Lucida Grande";
12 font-size: 12px;
15 body {
16 background: #fff;
17 color: #666;
20 h1 {
21 font-size: 15px;
22 font-weight: bold;
23 margin: 0 0 5px 0;
26 h2 {
27 font-size: 13px;
28 font-weight: bold;
29 margin: 5px 0 5px 0;
32 ol, ul {
33 margin: 10px 0 10px 0;
34 list-style-position: inside;
37 p {
38 margin: 5px 0 5px 0;
41 .content {
42 border: 1px dotted #444;
43 margin: 10px;
44 padding: 10px;
45 text-align: justify;
46 width: 700px;
49 .example {
50 border: 1px solid #ccc;
51 background: #eee;
52 margin: 10px;
53 padding: 10px;
55 </style>
56 </head>
58 <body>
59 <div class="content">
60 <h1>Table Library</h1>
62 <p>The table library provides an interface to auto-generate HTML tables from arrays or database result sets.</p>
63 </div>
65 <div class="content">
66 <h1>Example Tables</h1>
68 <p>This is an example showing how you can generate a table from a multi-dimensional array. The first array
69 index must be the headings for the table cells. You can also use <b>set_heading()</b> to set table cell
70 headings.</p>
72 <div class="example">
73 $this->load->library('table');<br />
74 <br />
75 $data = array(<br />
76 &nbsp;&nbsp;&nbsp;&nbsp;array('Name, 'Colour', 'Size'),<br />
77 &nbsp;&nbsp;&nbsp;&nbsp;array('Charlie', 'Blue', 'Small'),<br />
78 &nbsp;&nbsp;&nbsp;&nbsp;array('Emily', 'Green', 'Medium'),<br />
79 &nbsp;&nbsp;&nbsp;&nbsp;array('Simon', 'Red', 'Large')<br />
80 );<br />
81 <br />
82 echo $this->table->generate($data);
83 </div>
85 <p>You can also generate tables from database query results. The table class will automatically generate
86 table headings based on the field names of the table. You can also use the <b>set_heading()</b> method.</p>
88 <div class="example">
89 $this->load->library('table');<br />
90 <br />
91 $query = $this->db->query('SELECT * FROM `some_table`');<br />
92 <br />
93 echo $this->table->generate($query);
94 </div>
96 <p>You can also generate tables by individually passing the parameters to methods.</p>
98 <div class="example">
99 $this->load->library('table');<br />
100 <br />
101 $this->table->set_heading('Name, 'Colour', 'Size');<br />
102 <br />
103 $this->table->add_row('Charlie', 'Blue', 'Small');<br />
104 $this->table->add_row('Emily', 'Green', 'Medium');<br />
105 $this->table->add_row('Simon', 'Red', 'Large');<br />
106 <br />
107 echo $this->table->generate();
108 </div>
109 </div>
111 <div class="content">
112 <h1>Changing the Table Template</h1>
114 <p>The table library allows you to change the template that the library uses to generate the table layout.</p>
116 <div class="example">
117 $template = array (<br />
118 &nbsp;&nbsp;&nbsp;&nbsp;'table_open' => '&lt;table border="0" cellpadding="4" cellspacing="0"&gt;',<br />
119 <br />
120 &nbsp;&nbsp;&nbsp;&nbsp;'heading_row_start' => '&lt;tr&gt;',<br />
121 &nbsp;&nbsp;&nbsp;&nbsp;'heading_row_end' => '&lt;/tr&gt;',<br />
122 &nbsp;&nbsp;&nbsp;&nbsp;'heading_cell_start' => '&lt;th&gt;',<br />
123 &nbsp;&nbsp;&nbsp;&nbsp;'heading_cell_end' => '&lt;/th&gt;',<br />
124 <br />
125 &nbsp;&nbsp;&nbsp;&nbsp;'row_start' => '&lt;tr&gt;',<br />
126 &nbsp;&nbsp;&nbsp;&nbsp;'row_end' => '&lt;/tr&gt;',<br />
127 &nbsp;&nbsp;&nbsp;&nbsp;'cell_start' => '&lt;td&gt;',<br />
128 &nbsp;&nbsp;&nbsp;&nbsp;'cell_end' => '&lt;/td&gt;',<br />
129 <br />
130 &nbsp;&nbsp;&nbsp;&nbsp;'row_alt_start' => '&lt;tr&gt;',<br />
131 &nbsp;&nbsp;&nbsp;&nbsp;'row_alt_end' => '&lt;/tr&gt;',<br />
132 &nbsp;&nbsp;&nbsp;&nbsp;'cell_alt_start' => '&lt;td&gt;',<br />
133 &nbsp;&nbsp;&nbsp;&nbsp;'cell_alt_end' => '&lt;/td&gt;',<br />
134 <br />
135 &nbsp;&nbsp;&nbsp;&nbsp;'table_close' => '&lt;/table&gt;'<br />
136 );<br />
137 <br />
138 $this->table->set_template($template);
139 </div>
141 <p><i>Note</i>: you will notice there are two sets of 'row' elements. This allows you to create alternating
142 row colours or design elements that alternate with each other row.</p>
144 <p>You are not required to submit a template with every element changed. You only need to change parts of
145 the template you need.</p>
147 <div class="example">
148 $template = array( 'table_open' => '&lt;table cellpadding="2" cellspacing="1" class="tablebox"&gt;');<br />
149 <br />
150 $this->table->set_template($template);
151 </div>
152 </div>
154 <div class="content">
155 <h1>Table Class Methods</h1>
157 <h2>public function __construct()</h2>
158 <p>This method initialises the class.</p>
160 <h2>public function set_template($template)</h2>
161 <p>This method sets a user defined template <b>$template</b>.</p>
163 <h2>public function set_heading()</h2>
164 <p>This method sets the headings for the table cells.</p>
166 <h2>public function make_columns($array = array(), $col_limit = 0)</h2>
167 <p>This method takes an array as input and creates a multi-dimensional array with a depth of <b>$col_limit</b>.
168 This allows a single array with many elements to be displayed in a table that has a fixed column count.</p>
170 <h2>public function set_empty($value)</h2>
171 <p>This method sets the value to be displayed in empty table cells.</p>
173 <h2>public function add_row()</h2>
174 <p>This method lets you add a row to your table using either discreet parameters or an array.</p>
176 <h2>public function set_caption($caption)</h2>
177 <p>This method lets you set a caption for the table.</p>
179 <h2>public function generate($table_data = null)</h2>
180 <p>This method generates the table ready to be outputted.</p>
182 <h2>public function clear()</h2>
183 <p>This method clears any data in the table class so that you can create another table.</p>
185 <h2>private function c_set_from_object($query)</h2>
186 <p>This method sets the table data from the members of an object.</p>
188 <h2>private function c_set_from_array($data, $set_heading = true)</h2>
189 <p>This method sets the table data from an array.</p>
191 <h2>private function c_compile_template()</h2>
192 <p>This method compiles the table template ready for use.</p>
194 <h2>private function c_default_template()</h2>
195 <p>This method returns the default table template.</p>
196 </div>
197 </body>
199 </html>