- 2008-07-05 (土) 21:55
- CakePHP修行
今回はPearを使ってカレンダー表示ページを作成します。Pearとカレンダーパッケージについては以前にも参考にさせていただいたことのあるmukoさんのブログエントリーが分かりやすいです。コメントも含めて参考にさせていただきました。
creative@interactive ≫ CakePHPとカレンダー表示(2)
まずは下記のようにvendorフォルダにPEARとカレンダーパッケージを配置します。

・app/vendors/pear_ini.php
define('PEAR_PATH', dirname(__FILE__) . DS . 'PEAR');
ini_set('include_path', PEAR_PATH . PATH_SEPARATOR . ini_get('include_path'));
・app/controllers/schedules_controller.php
vendor("pear_ini");
vendor("PEAR/Calendar/Month/Weekdays");
class SchedulesController extends AppController
{
var $name = 'Schedules';
var $uses = array('Schedule');
function index($year = null, $month = null)
{
//スケジュール読み込み
$this->set('schedules', $this->Schedule->findAll());
if($year == null || $month == null)
{
$Month = new Calendar_Month_Weekdays( date('Y'), date('m'), 0 );
$year = date('Y');
$month = date('m');
} else {
$Month = new Calendar_Month_Weekdays( $year, $month, 0 );
}
//PEARよりカレンダー情報を読み込み
$Month->build();
$this->set('month', $Month);
}
}
・app/views/schedules/index.thtml
<h1> - Test - </h1>
<!-- ▼calendar -->
<div id="calendar">
<table border="0">
<tr>
<th>Sun</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
< ?php
while ($Day = $month->fetch()) {
if ($Day->isFirst()) {
echo "<tr>\n";
}
if ($Day->isEmpty()) {
echo "<td>&nbsp;</td>\n";
} else {
echo "<td>" . $Day->thisDay() . "</td>\n";
}
if ($Day->isLast()) {
echo "</tr>\n";
}
}
?>
</table>
</div>
<!-- ▲calendar -->
コメント:0
トラックバック:0
- このエントリーへのトラックバックURL
- http://www.studio-kingdom.com/cakephp/cakephp_training/72/trackback