blob: 9d2a01e1b9348ee3356ce58d93bdce3a19710b25 [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
admin17a890d2006-09-27 20:42:42 +000010<script type="text/javascript" src="../nav/nav.js"></script>
admin2296fc32006-09-27 21:07:02 +000011<script type="text/javascript" src="../nav/prototype.lite.js"></script>
admin17a890d2006-09-27 20:42:42 +000012<script type="text/javascript" src="../nav/moo.fx.js"></script>
adminb0dd10f2006-08-25 17:25:49 +000013<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>
admin10c3f412006-10-08 07:21:12 +000036<td><h1>Code Igniter User Guide Version 1.5.0b1</h1></td>
adminb0dd10f2006-08-25 17:25:49 +000037<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;
50Calendaring 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
65
66<h1>Calendaring Class</h1>
67
68<p>The Calendar class enables you to dynamically create calendars. Your calendars can be formatted through the use of a calendar
69template, allowing 100% control over every aspect of its design. In addition, you can pass data to your calendar cells.</p>
70
71<h2>Initializing the Class</h2>
72
73<p>Like most other classes in Code Igniter, the Calendar class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
74
75<code>$this->load->library('calendar');</code>
76<p>Once loaded, the Calendar object will be available using: <dfn>$this->calendar</dfn></p>
77
adminb1fddc02006-10-09 21:29:07 +000078<p>You can also set your own class variable name. Please see the <a href="loader.html">Loader Class</a> for more info.</p>
79
adminb0dd10f2006-08-25 17:25:49 +000080
81<h2>Displaying a Calendar</h2>
82
83<p>Here is a very simple example showing how you can display a calendar:</p>
84
85<code>$this->load->library('calendar');<br />
86<br />
87echo $this->calendar->generate();</code>
88
89<p>The above code will generate a calendar for the current month/year based on your server time.
90To show a calendar for a specific month and year you will pass this information to the calendar generating function:</p>
91
92<code>$this->load->library('calendar');<br />
93<br />
94echo $this->calendar->generate(<kbd>2006</kbd>, <kbd>6</kbd>);</code>
95
96<p>The above code will generate a calendar showing the month of June in 2006. The first parameter specifies the year, the second parameter specifies the month.</p>
97
98<h2>Passing Data to your Calendar Cells</h2>
99
100<p>To add data to your calendar cells involves creating an associative array in which the keys correspond to the days
101you wish to populate and the array value contains the data. The array is passed to the third parameter of the calendar
102generating function. Consider this example:</p>
103
104<code>$this->load->library('calendar');<br />
105<br />
106$data = array(<br />
107&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3&nbsp; => 'http://your-site.com/news/article/2006/03/',<br />
108&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7&nbsp; => 'http://your-site.com/news/article/2006/07/',<br />
109&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;13 => 'http://your-site.com/news/article/2006/13/',<br />
110&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;26 => 'http://your-site.com/news/article/2006/26/'<br />
111&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
112<br />
113echo $this->calendar->generate(<kbd>2006</kbd>, <kbd>6</kbd>, <var>$data</var>);</code>
114
115<p>Using the above example, day numbers 3, 7, 13, and 26 will become links pointing to the URLs you've provided.</p>
116
117<p class="important"><strong>Note:</strong> By default it is assumed that your array will contain links.
118In the section that explains the calendar template below you'll see how you can customize
119how data passed to your cells is handled so you can pass different types of information.</p>
120
121
122<h2>Setting Display Preferences</h2>
123
124<p>There are seven preferences you can set to control various aspects of the calendar. Preferences are set using an initialization
125function similar to other classes. Here is an example:
126
127
128<code>$this->load->library('calendar');<br />
129<br />
130$prefs = array (<br />
131&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'start_day'&nbsp;&nbsp;&nbsp; => 'saturday',<br />
132&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'month_type'&nbsp;&nbsp; => 'long',<br />
133&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'day_type'&nbsp;&nbsp;&nbsp;&nbsp; => 'short'<br />
134&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
135<br />
136$this->calendar->initialize($prefs);<br />
137<br />
138echo $this->calendar->generate();</code>
139
140<p>The above code would start the calendar on saturday, use the "long" month heading, and the "short" day names. More information
141regarding preferences below.</p>
142
143
144
145
146<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
147<tr>
148<th>Preference</th>
149<th>Default&nbsp;Value</th>
150<th>Options</th>
151<th>Description</th>
152</tr><tr>
153<td class="td"><strong>template</strong></td><td class="td">None</td><td class="td">None</td><td class="td">A string containing your calendar template. See the template section below.</td>
154</tr><tr>
155<td class="td"><strong>local_time</strong></td><td class="td">time()</td><td class="td">None</td><td class="td">A Unix timestamp corresponding to the current time.</td>
156</tr><tr>
157<td class="td"><strong>start_day</strong></td><td class="td">sunday</td><td class="td">Any week day (sunday, monday, tuesday, etc.)</td><td class="td">Sets the day of the week the calendar should start on.</td>
158</tr><tr>
159<td class="td"><strong>month_type</strong></td><td class="td">long</td><td class="td">long, short</td><td class="td">Determines what version of the month name to use in the header. long = January, short = Jan.</td>
160</tr><tr>
161<td class="td"><strong>day_type</strong></td><td class="td">abr</td><td class="td">long, short, abr</td><td class="td">Determines what version of the weekday names to use in the column headers. long = Sunday, short = Sun, abr = Su.</td>
162</tr><tr>
163<td class="td"><strong>show_next_prev</strong></td><td class="td">FALSE</td><td class="td">TRUE/FALSE (boolean)</td><td class="td">Determines whether to display links allowing you to toggle to next/previous months. See information on this feature below.</td>
164</tr><tr>
165<td class="td"><strong>next_prev_url</strong></td><td class="td">None</td><td class="td">A URL</td><td class="td">Sets the basepath used in the next/previous calendar links.</td>
166</tr>
167</table>
168
169
170
171
172<h2>Creating a Calendar Template</h2>
173
174<p>By creating a calendar template you have 100% control over the design of your calendar. Each component of your
175calendar will be placed within a pair of pseudo-variables as shown here:</p>
176
177
178<code>$this->load->library('calendar');<br /><br />
179$prefs['template'] = '<br /><br />
180&nbsp;&nbsp;&nbsp;<dfn>{table_open}</dfn><var>&lt;table border="0" cellpadding="0" cellspacing="0"></var><dfn>{/table_open}</dfn><br />
181<br />
182&nbsp;&nbsp;&nbsp;<dfn>{heading_row_start}</dfn><var>&lt;tr></var><dfn>{/heading_row_start}</dfn><br />
183<br />
184&nbsp;&nbsp;&nbsp;<dfn>{heading_previous_cell}</dfn><var>&lt;th>&lt;a href="</var><kbd>{previous_url}</kbd><var>">&amp;lt;&amp;lt;&lt;/a>&lt;/th></var><dfn>{/heading_previous_cell}</dfn><br />
185&nbsp;&nbsp;&nbsp;<dfn>{heading_title_cell}</dfn><var>&lt;th colspan="</var><kbd>{colspan}</kbd><var>"></var><kbd>{heading}</kbd><var>&lt;/th></var><dfn>{/heading_title_cell}</dfn><br />
186&nbsp;&nbsp;&nbsp;<dfn>{heading_next_cell}</dfn><var>&lt;th>&lt;a href="</var><kbd>{next_url}</kbd><var>">&amp;gt;&amp;gt;&lt;/a>&lt;/th></var><dfn>{/heading_next_cell}</dfn><br />
187<br />
188&nbsp;&nbsp;&nbsp;<dfn>{heading_row_end}</dfn><var>&lt;/tr></var><dfn>{/heading_row_end}</dfn><br />
189<br />
190&nbsp;&nbsp;&nbsp;<dfn>{week_row_start}</dfn><var>&lt;tr></var><dfn>{/week_row_start}</dfn><br />
191&nbsp;&nbsp;&nbsp;<dfn>{week_day_cell}</dfn><var>&lt;td></var><dfn>{week_day}</dfn><var>&lt;/td></var><dfn>{/week_day_cell}</dfn><br />
192&nbsp;&nbsp;&nbsp;<dfn>{week_row_end}</dfn><var>&lt;/tr></var><dfn>{/week_row_end}</dfn><br />
193<br />
194&nbsp;&nbsp;&nbsp;<dfn>{cal_row_start}</dfn><var>&lt;tr></var><dfn>{/cal_row_start}</dfn><br />
195&nbsp;&nbsp;&nbsp;<dfn>{cal_cell_start}</dfn><var>&lt;td></var><dfn>{/cal_cell_start}</dfn><br />
196<br />
197&nbsp;&nbsp;&nbsp;<dfn>{cal_cell_content}</dfn><var>&lt;a href="</var><kbd>{content}</kbd><var>"></var><kbd>{day}</kbd><var>&lt;/a></var><dfn>{/cal_cell_content}</dfn><br />
198&nbsp;&nbsp;&nbsp;<dfn>{cal_cell_content_today}</dfn><var>&lt;div class="highlight">&lt;a href="</var><kbd>{content}</kbd><var>"></var><kbd>{day}</kbd><var>&lt;/a>&lt;/div></var><dfn>{/cal_cell_content_today}</dfn><br />
199<br />
200&nbsp;&nbsp;&nbsp;<dfn>{cal_cell_no_content}</dfn><var></var><kbd>{day}</kbd><var></var><dfn>{/cal_cell_no_content}</dfn><br />
201&nbsp;&nbsp;&nbsp;<dfn>{cal_cell_no_content_today}</dfn><var>&lt;div class="highlight"></var><kbd>{day}</kbd><var>&lt;/div></var><dfn>{/cal_cell_no_content_today}</dfn><br />
202<br />
203&nbsp;&nbsp;&nbsp;<dfn>{cal_cell_blank}</dfn><var>&amp;nbsp;</var><dfn>{/cal_cell_blank}</dfn><br />
204<br />
205&nbsp;&nbsp;&nbsp;<dfn>{cal_cell_end}</dfn><var>&lt;/td></var><dfn>{/cal_cell_end}</dfn><br />
adminc1fa0742006-09-21 23:50:23 +0000206&nbsp;&nbsp;&nbsp;<dfn>{cal_row_end}</dfn><var>&lt;/tr></var><dfn>{/cal_row_end}</dfn><br />
adminb0dd10f2006-08-25 17:25:49 +0000207<br />
208&nbsp;&nbsp;&nbsp;<dfn>{table_close}</dfn><var>&lt;/table></var><dfn>{/table_close}</dfn><br />
209';<br />
210<br />
211$this->calendar->initialize($prefs);<br />
212<br />
213echo $this->calendar->generate();</code>
214
215
216
217<h2>Showing Next/Previous Month Links</h2>
218
219<p>To allow your calendar to dynamically increment/decrement via the next/previous links requires that you set up your calendar
220code similar to this example:</p>
221
222
223<code>$this->load->library('calendar');<br />
224<br />
225$prefs = array (<br />
226&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'show_next_prev'&nbsp;&nbsp;=> TRUE,<br />
227&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'next_prev_url'&nbsp;&nbsp; => 'http://www.your-site.com/index.php/calendar/show/'<br />
228&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
229<br />
230$this->calendar->initialize($prefs);<br />
231<br />
232echo $this->calendar->generate(<var>$this->uri->segment(3)</var>, <var>$this->uri->segment(4)</var>);</code>
233
234<p>You'll notice a few things about the above example:</p>
235
236<ul>
237<li>You must set the "show_next_prev" to TRUE.</li>
238<li>You must supply the URL to the controller containing your calendar in the "next_prev_url" preference.</li>
239<li>You must supply the "year" and "month" to the calendar generating function via the URI segments where they appear (Note: The calendar class automatically adds the year/month to the base URL you provide.).</li>
240</ul>
241
242
243
244</div>
245<!-- END CONTENT -->
246
247
248<div id="footer">
249<p>
250Previous Topic:&nbsp;&nbsp;<a href="benchmark.html">Benchmarking Class</a>
251&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
252<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
253<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
254Next Topic:&nbsp;&nbsp;<a href="config.html">Config Class</a>
255<p>
256<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>
257</div>
258
259</body>
260</html>