カレンダーページを作成(CakePHP修行 #6)

  • 2008-07-05 (土) 21:55

今回はPearを使ってカレンダー表示ページを作成します。Pearとカレンダーパッケージについては以前にも参考にさせていただいたことのあるmukoさんのブログエントリーが分かりやすいです。コメントも含めて参考にさせていただきました。

creative@interactive ≫ CakePHPとカレンダー表示(2)

まずは下記のようにvendorフォルダにPEARとカレンダーパッケージを配置します。

vendor_pear.gif

・app/vendors/pear_ini.php
[sourcecode language='php']
define(‘PEAR_PATH’, dirname(__FILE__) . DS . ‘PEAR’);
ini_set(‘include_path’, PEAR_PATH . PATH_SEPARATOR . ini_get(‘include_path’));
[/sourcecode]

・app/controllers/schedules_controller.php
[sourcecode language='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);
}
}
[/sourcecode]

・app/views/schedules/index.thtml
[sourcecode language='php']

– Test –

< ?php
while ($Day = $month->fetch()) {
if ($Day->isFirst()) {
echo “

\n”;
}
if ($Day->isEmpty()) {
echo “

\n”;
} else {
echo “

\n”;
}
if ($Day->isLast()) {
echo “

\n”;
}
}
?>

Sun Mon Tue Wed Thu Fri Sat
&nbsp; ” . $Day->thisDay() . “


[/sourcecode]

ここまでやれば下記のような感じでカレンダーページが表示されると思います。
clbs_cal_page.gif

コメント:0

コメントフォーム
Remember personal info

トラックバック:0

このエントリーへのトラックバックURL
http://www.studio-kingdom.com/cakephp/cakephp_training/72/trackback
フィード

メタ

Return to page top