Home > CakePHP
CakePHP Archive
dispatcher.php – $this->parseParams($url) (CakePHP解析 #9)
- 2008-08-11 (月)
- CakePHP解析
今回は$Route->parseから戻ってparseParamsメソッドの解析をします。
以前解析したように$Route->parse(‘users/login/aaaa/bbbb/cccc/dddd?a=A&b=B’)の戻り値は
下記のような配列になります。
Array ( [pass] => Array ( [0] => aaaa [1] => bbbb [2] => cccc [3] => dddd ) [controller] => users [action] => login )
この結果を$params変数が受け取っているわけですが、この$params変数は「$this->data」を保持する非常に重要な変数です。
下記のようにその後の処理でform値やurl値を取り込んでいます。
[sourcecode language='php']
if (ini_get(‘magic_quotes_gpc’) == 1) {
if (!empty($_POST)) {
$params['form'] = stripslashes_deep($_POST);
}
} else {
$params['form'] = $_POST;
}
[/sourcecode]
次回はこの処理の中で使用されている「stripslashes_deep」関数を解析します。
登録したスケジュールをカレンダーに表示(CakePHP修行 #9)
- 2008-07-27 (日)
- CakePHP修行
今回はカレンダーページ上に、登録したスケジュールのタイトルを表示する処理を実装します。
コントローラーのCalendarアクションを変更します。
・app/controllers/schedules_controller.php
[sourcecode language='php']
//calendar
function calendar($year = null, $month = null){
//システムメッセージをセット
$this->set(‘sys_msg’, $this->Session->read(‘sys_msg’));
$this->Session->delete(‘sys_msg’);
//指定された年月を取得/指定なしの場合はシステム日付を取得
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);
//取得した年月、次月、前月をYYYY/MM形式で変数にセット
$this->set(‘next_year_month’, date(“Y/m”, mktime(0, 0, 0, $month+1, 1, $year)));
$this->set(‘this_year_month’, date(“Y/m”, mktime(0, 0, 0, $month, 1, $year)));
$this->set(‘prev_year_month’, date(“Y/m”, mktime(0, 0, 0, $month-1, 1, $year)));
//取得した年月のスケジュール情報をScheduleから取得
$cond = array(
‘AND’ => array(
array(“Schedule.start” => “>=$year-$month-01″)
,array(“Schedule.start” => “< =$year-$month-31")
)
);
$this->set(‘schedules’, $this->Schedule->findAll($cond));
}
[/sourcecode]
スケジュール登録処理を作成(CakePHP修行 #8)
- 2008-07-18 (金)
- CakePHP修行
今回はスケジュール登録画面を作成します。
今回は(1)スケジュール登録ページのリンク→(2)登録ページ→(3)登録処理→(4)登録完了メッセージの表示、と
順を追って説明していきます。
ちなみに完成画像はこちら↓
(1)スケジュール登録ページのリンク
・app/view/schelue/calendar.thtml
※前回まで、app/view/schelue/index.thtmlだったファイルをcalendar.thtmlに変更しました。
まずは、カレンダーページの日付セル内にそれぞれ日付登録ページへのリンクを張ります。
ここでリンク画像にfamfamfamさんの画像を使用します。
画像形式がPNGなので、IE6対策を施しておきます。
IE6のPNG画像透過処理を行ってくれるto-Rさんが作成された便利なjsライブラリがあるので、
それを利用させていただきます。ダウンロードしたjsファイルをapp/webroot/jsフォルダに入れてください。
リンクをこんな風に記述。
[sourcecode language='php']
echo $html->link($html->image(“pencil_add.png” , array(“class”=>”alphafilter”)), ‘/schedules/add/’ . $month->year . “/” . $month->month . “/” . $Day->thisDay(),null,null,false);
[/sourcecode]
また、ダウンロードしたjsファイルを読み込むために、レイアウトのデフォルトファイルにjsファイル読み込みの記述を追加します。
後述するjqueryファイルも同じように追記します。
・app/views/layouts/default.thtml
[sourcecode language='php']
[/sourcecode]
ホーム > CakePHP