admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
Derek Allard | afd99ac | 2008-01-19 19:59:14 +0000 | [diff] [blame] | 2 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 3 | <head>
|
| 4 |
|
Derek Allard | 8039d4c | 2008-05-31 02:47:56 +0000 | [diff] [blame] | 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
Derek Jones | fd93d22 | 2008-05-06 15:18:50 +0000 | [diff] [blame] | 6 | <title>Calendaring Class : CodeIgniter User Guide</title>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 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 |
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 11 | <script type="text/javascript" src="../nav/nav.js"></script>
|
admin | 2296fc3 | 2006-09-27 21:07:02 +0000 | [diff] [blame] | 12 | <script type="text/javascript" src="../nav/prototype.lite.js"></script>
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 13 | <script type="text/javascript" src="../nav/moo.fx.js"></script>
|
Derek Allard | b341237 | 2007-10-25 12:15:16 +0000 | [diff] [blame] | 14 | <script type="text/javascript" src="../nav/user_guide_menu.js"></script>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 15 |
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 16 | <meta http-equiv='expires' content='-1' />
|
| 17 | <meta http-equiv= 'pragma' content='no-cache' />
|
| 18 | <meta name='robots' content='all' />
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 19 | <meta name='author' content='ExpressionEngine Dev Team' />
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 20 | <meta name='description' content='CodeIgniter User Guide' />
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 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.jpg" width="153" height="44" 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>
|
Derek Jones | 1ca3fc4 | 2008-06-27 00:19:33 +0000 | [diff] [blame] | 31 | <td><h1>CodeIgniter User Guide Version 1.6.3</h1></td>
|
admin | c0d5d52 | 2006-10-30 19:40:35 +0000 | [diff] [blame] | 32 | <td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 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">
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 43 | <a href="http://codeigniter.com/">CodeIgniter Home</a> ›
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 44 | <a href="../index.html">User Guide Home</a> ›
|
| 45 | Calendaring Class
|
| 46 | </td>
|
Derek Allard | bc03091 | 2007-06-24 18:25:29 +0000 | [diff] [blame] | 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>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 48 | </tr>
|
| 49 | </table>
|
| 50 | <!-- END BREADCRUMB -->
|
| 51 |
|
| 52 | <br clear="all" />
|
| 53 |
|
| 54 |
|
| 55 | <!-- START CONTENT -->
|
| 56 | <div id="content">
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 | <h1>Calendaring Class</h1>
|
| 62 |
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 63 | <p>The Calendar class enables you to dynamically create calendars. Your calendars can be formatted through the use of a calendar
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 64 | template, allowing 100% control over every aspect of its design. In addition, you can pass data to your calendar cells.</p>
|
| 65 |
|
| 66 | <h2>Initializing the Class</h2>
|
| 67 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 68 | <p>Like most other classes in CodeIgniter, the Calendar class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 69 |
|
| 70 | <code>$this->load->library('calendar');</code>
|
| 71 | <p>Once loaded, the Calendar object will be available using: <dfn>$this->calendar</dfn></p>
|
| 72 |
|
| 73 |
|
| 74 | <h2>Displaying a Calendar</h2>
|
| 75 |
|
| 76 | <p>Here is a very simple example showing how you can display a calendar:</p>
|
| 77 |
|
| 78 | <code>$this->load->library('calendar');<br />
|
| 79 | <br />
|
| 80 | echo $this->calendar->generate();</code>
|
| 81 |
|
| 82 | <p>The above code will generate a calendar for the current month/year based on your server time.
|
| 83 | To show a calendar for a specific month and year you will pass this information to the calendar generating function:</p>
|
| 84 |
|
| 85 | <code>$this->load->library('calendar');<br />
|
| 86 | <br />
|
| 87 | echo $this->calendar->generate(<kbd>2006</kbd>, <kbd>6</kbd>);</code>
|
| 88 |
|
| 89 | <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>
|
| 90 |
|
| 91 | <h2>Passing Data to your Calendar Cells</h2>
|
| 92 |
|
| 93 | <p>To add data to your calendar cells involves creating an associative array in which the keys correspond to the days
|
| 94 | you wish to populate and the array value contains the data. The array is passed to the third parameter of the calendar
|
| 95 | generating function. Consider this example:</p>
|
| 96 |
|
| 97 | <code>$this->load->library('calendar');<br />
|
| 98 | <br />
|
| 99 | $data = array(<br />
|
Derek Jones | ff845f9 | 2008-06-26 17:05:55 +0000 | [diff] [blame] | 100 | 3 => 'http://example.com/news/article/2006/03/',<br />
|
| 101 | 7 => 'http://example.com/news/article/2006/07/',<br />
|
| 102 | 13 => 'http://example.com/news/article/2006/13/',<br />
|
| 103 | 26 => 'http://example.com/news/article/2006/26/'<br />
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 104 | );<br />
|
| 105 | <br />
|
| 106 | echo $this->calendar->generate(<kbd>2006</kbd>, <kbd>6</kbd>, <var>$data</var>);</code>
|
| 107 |
|
| 108 | <p>Using the above example, day numbers 3, 7, 13, and 26 will become links pointing to the URLs you've provided.</p>
|
| 109 |
|
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 110 | <p class="important"><strong>Note:</strong> By default it is assumed that your array will contain links.
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 111 | In the section that explains the calendar template below you'll see how you can customize
|
| 112 | how data passed to your cells is handled so you can pass different types of information.</p>
|
| 113 |
|
| 114 |
|
| 115 | <h2>Setting Display Preferences</h2>
|
| 116 |
|
admin | b93464d | 2006-10-31 00:36:32 +0000 | [diff] [blame] | 117 | <p>There are seven preferences you can set to control various aspects of the calendar. Preferences are set by passing an
|
| 118 | array of preferences in the second parameter of the loading function. Here is an example:</p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 119 |
|
| 120 |
|
admin | b93464d | 2006-10-31 00:36:32 +0000 | [diff] [blame] | 121 | <code>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 122 | $prefs = array (<br />
|
| 123 | 'start_day' => 'saturday',<br />
|
| 124 | 'month_type' => 'long',<br />
|
| 125 | 'day_type' => 'short'<br />
|
| 126 | );<br />
|
| 127 | <br />
|
admin | b93464d | 2006-10-31 00:36:32 +0000 | [diff] [blame] | 128 | $this->load->library('calendar', $prefs);<br />
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 129 | <br />
|
| 130 | echo $this->calendar->generate();</code>
|
| 131 |
|
| 132 | <p>The above code would start the calendar on saturday, use the "long" month heading, and the "short" day names. More information
|
| 133 | regarding preferences below.</p>
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 | <table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
|
| 139 | <tr>
|
| 140 | <th>Preference</th>
|
| 141 | <th>Default Value</th>
|
| 142 | <th>Options</th>
|
| 143 | <th>Description</th>
|
| 144 | </tr><tr>
|
| 145 | <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>
|
| 146 | </tr><tr>
|
| 147 | <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>
|
| 148 | </tr><tr>
|
| 149 | <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>
|
| 150 | </tr><tr>
|
| 151 | <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>
|
| 152 | </tr><tr>
|
| 153 | <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>
|
| 154 | </tr><tr>
|
| 155 | <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>
|
| 156 | </tr><tr>
|
| 157 | <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>
|
| 158 | </tr>
|
| 159 | </table>
|
| 160 |
|
| 161 |
|
| 162 |
|
admin | b93464d | 2006-10-31 00:36:32 +0000 | [diff] [blame] | 163 | <h2>Showing Next/Previous Month Links</h2>
|
| 164 |
|
| 165 | <p>To allow your calendar to dynamically increment/decrement via the next/previous links requires that you set up your calendar
|
| 166 | code similar to this example:</p>
|
| 167 |
|
| 168 |
|
Derek Allard | 08e6b0c | 2007-08-23 01:04:53 +0000 | [diff] [blame] | 169 | <code>$prefs = array (<br />
|
admin | b93464d | 2006-10-31 00:36:32 +0000 | [diff] [blame] | 170 | 'show_next_prev' => TRUE,<br />
|
Derek Jones | ff845f9 | 2008-06-26 17:05:55 +0000 | [diff] [blame] | 171 | 'next_prev_url' => 'http://example.com/index.php/calendar/show/'<br />
|
admin | b93464d | 2006-10-31 00:36:32 +0000 | [diff] [blame] | 172 | );<br />
|
| 173 | <br />
|
Derek Allard | 08e6b0c | 2007-08-23 01:04:53 +0000 | [diff] [blame] | 174 | $this->load->library('calendar', $prefs);<br />
|
| 175 | <br />
|
| 176 | echo $this->calendar->generate(<var>$this->uri->segment(3)</var>, <var>$this->uri->segment(4)</var>);</code>
|
admin | b93464d | 2006-10-31 00:36:32 +0000 | [diff] [blame] | 177 |
|
| 178 | <p>You'll notice a few things about the above example:</p>
|
| 179 |
|
| 180 | <ul>
|
| 181 | <li>You must set the "show_next_prev" to TRUE.</li>
|
| 182 | <li>You must supply the URL to the controller containing your calendar in the "next_prev_url" preference.</li>
|
| 183 | <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>
|
| 184 | </ul>
|
| 185 |
|
| 186 |
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 187 |
|
| 188 | <h2>Creating a Calendar Template</h2>
|
| 189 |
|
| 190 | <p>By creating a calendar template you have 100% control over the design of your calendar. Each component of your
|
| 191 | calendar will be placed within a pair of pseudo-variables as shown here:</p>
|
| 192 |
|
| 193 |
|
admin | b93464d | 2006-10-31 00:36:32 +0000 | [diff] [blame] | 194 | <code>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 195 | $prefs['template'] = '<br /><br />
|
| 196 | <dfn>{table_open}</dfn><var><table border="0" cellpadding="0" cellspacing="0"></var><dfn>{/table_open}</dfn><br />
|
| 197 | <br />
|
| 198 | <dfn>{heading_row_start}</dfn><var><tr></var><dfn>{/heading_row_start}</dfn><br />
|
| 199 | <br />
|
| 200 | <dfn>{heading_previous_cell}</dfn><var><th><a href="</var><kbd>{previous_url}</kbd><var>">&lt;&lt;</a></th></var><dfn>{/heading_previous_cell}</dfn><br />
|
| 201 | <dfn>{heading_title_cell}</dfn><var><th colspan="</var><kbd>{colspan}</kbd><var>"></var><kbd>{heading}</kbd><var></th></var><dfn>{/heading_title_cell}</dfn><br />
|
| 202 | <dfn>{heading_next_cell}</dfn><var><th><a href="</var><kbd>{next_url}</kbd><var>">&gt;&gt;</a></th></var><dfn>{/heading_next_cell}</dfn><br />
|
| 203 | <br />
|
| 204 | <dfn>{heading_row_end}</dfn><var></tr></var><dfn>{/heading_row_end}</dfn><br />
|
| 205 | <br />
|
| 206 | <dfn>{week_row_start}</dfn><var><tr></var><dfn>{/week_row_start}</dfn><br />
|
| 207 | <dfn>{week_day_cell}</dfn><var><td></var><dfn>{week_day}</dfn><var></td></var><dfn>{/week_day_cell}</dfn><br />
|
| 208 | <dfn>{week_row_end}</dfn><var></tr></var><dfn>{/week_row_end}</dfn><br />
|
| 209 | <br />
|
| 210 | <dfn>{cal_row_start}</dfn><var><tr></var><dfn>{/cal_row_start}</dfn><br />
|
| 211 | <dfn>{cal_cell_start}</dfn><var><td></var><dfn>{/cal_cell_start}</dfn><br />
|
| 212 | <br />
|
| 213 | <dfn>{cal_cell_content}</dfn><var><a href="</var><kbd>{content}</kbd><var>"></var><kbd>{day}</kbd><var></a></var><dfn>{/cal_cell_content}</dfn><br />
|
| 214 | <dfn>{cal_cell_content_today}</dfn><var><div class="highlight"><a href="</var><kbd>{content}</kbd><var>"></var><kbd>{day}</kbd><var></a></div></var><dfn>{/cal_cell_content_today}</dfn><br />
|
| 215 | <br />
|
| 216 | <dfn>{cal_cell_no_content}</dfn><var></var><kbd>{day}</kbd><var></var><dfn>{/cal_cell_no_content}</dfn><br />
|
| 217 | <dfn>{cal_cell_no_content_today}</dfn><var><div class="highlight"></var><kbd>{day}</kbd><var></div></var><dfn>{/cal_cell_no_content_today}</dfn><br />
|
| 218 | <br />
|
| 219 | <dfn>{cal_cell_blank}</dfn><var>&nbsp;</var><dfn>{/cal_cell_blank}</dfn><br />
|
| 220 | <br />
|
| 221 | <dfn>{cal_cell_end}</dfn><var></td></var><dfn>{/cal_cell_end}</dfn><br />
|
admin | c1fa074 | 2006-09-21 23:50:23 +0000 | [diff] [blame] | 222 | <dfn>{cal_row_end}</dfn><var></tr></var><dfn>{/cal_row_end}</dfn><br />
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 223 | <br />
|
| 224 | <dfn>{table_close}</dfn><var></table></var><dfn>{/table_close}</dfn><br />
|
| 225 | ';<br />
|
| 226 | <br />
|
admin | b93464d | 2006-10-31 00:36:32 +0000 | [diff] [blame] | 227 | $this->load->library('calendar', $prefs);<br />
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 228 | <br />
|
| 229 | echo $this->calendar->generate();</code>
|
| 230 |
|
| 231 |
|
| 232 |
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 233 | </div>
|
| 234 | <!-- END CONTENT -->
|
| 235 |
|
| 236 |
|
| 237 | <div id="footer">
|
| 238 | <p>
|
| 239 | Previous Topic: <a href="benchmark.html">Benchmarking Class</a>
|
| 240 | ·
|
| 241 | <a href="#top">Top of Page</a> ·
|
| 242 | <a href="../index.html">User Guide Home</a> ·
|
| 243 | Next Topic: <a href="config.html">Config Class</a>
|
Derek Allard | c644128 | 2007-07-04 23:54:32 +0000 | [diff] [blame] | 244 | </p>
|
Derek Jones | 0787043 | 2008-02-13 03:49:26 +0000 | [diff] [blame] | 245 | <p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 246 | </div>
|
| 247 |
|
| 248 | </body>
|
| 249 | </html> |