cakephpでpearを使う2
たとえば、pearへのインクルードパスが指定できる。とか、.htaccessでインクルードパスを変えれる時に
cakephp で pear を使う場合はそのまま使えないのかと思いました。
(いろいろ参考にしてるとvendorsの中に入れるみたいで・・・)
で、実験してみました。
ヘルパーでpearCalendarを使ってみました。
';
';
}
//週の表示
function week($schedules=null, $times=null){
$week = new Calendar_Week(date('Y',$times['from_time']), date('m',$times['from_time']),date('d',$times['from_time']), 0);
$week->build();
echo '';
';
}
//日の表示
function day($schedules=null, $times=null){
}
function dayLink($time) {
$out = strftime('%m/%d', $time).__(strftime('(%a)', $time), true);
$out = $this->Html->link($out, array('action'=>'index', 'id'=>'day', date('Y/m/d',$time)));
return $out;
}
//***************************************************************
// 表示別ナビゲーション
//***************************************************************
function navi($controller, $scope, $current) {
$method = $scope.'_navi';
return $this->$method($controller, $current);
}
//月の場合
function month_navi($controller, $current) {
$url = $this->params['controller'].'/'.$this->params['action'];
list($year, $month, $day) = split('/',$current);
//先月
echo $this->Html->link('先月','/'.$url.'/month/'.date('Y/m/',mktime(0,0,0,$month-1,1,$year)),array('id'=>'btn','class'=>'lastmonth'));
//今月
echo $this->Html->link('今月','/'.$url.'/month/'.date('Y/m/'),array('id'=>'btn','class'=>'thismonth'));
//翌月
echo $this->Html->link('翌月','/'.$url.'/month/'.date('Y/m/',mktime(0,0,0,$month+1,1,$year)),array('id'=>'btn','class'=>'nextmonth'));
}
//週の場合
function week_navi($controller, $current) {
$url = $this->params['controller'].'/'.$this->params['action'];
list($year, $month, $day) = split('/', $current);
//先週
echo $this->Html->link('先週','/'.$url.'/week/'.date('Y/m/d', mktime(0,0,0,$month,$day-7,$year)),array('id'=>'btn','class'=>'lastweek'));
//今週
echo $this->Html->link('今週','/'.$url.'/week/'.date('Y/m/d'),array('id'=>'btn','class'=>'thisweek'));
//翌週
echo $this->Html->link('翌週','/'.$url.'/week/'.date('Y/m/d', mktime(0,0,0,$month,$day+7,$year)),array('id'=>'btn','class'=>'nextweek'));
}
//日の場合
function day_navi($controller, $current) {
$out = '
return $out;
}
}
?>
という感じで上手くいきました。
クラスとかがもっと理解できれば・・・。と思いますが、今度pearのpagerを使ったページ送りを試してみたいと思います。
cakephp で pear を使う場合はそのまま使えないのかと思いました。
(いろいろ参考にしてるとvendorsの中に入れるみたいで・・・)
で、実験してみました。
ヘルパーでpearCalendarを使ってみました。
//カレンダーの読み込み
require_once 'Calendar/Month/Weekdays.php';
require_once("Calendar/Month.php");
require_once("Calendar/Week.php");
require_once("Calendar/Day.php");
require_once("Calendar/Hour.php");
class ScheduleTableHelper extends Helper {
var $helpers = array('Html');
//月の表示
function month($schedules=null, $times=null) {
$month = new Calendar_Month_Weekdays(date('Y',$times['from_time']), date('n',$times['from_time']), 0);
$month->build();
echo '
日 | 月 | 火 | 水 | 木 | 金 | 土 | ';
---|---|
'."\n"; | '.''.$Day->thisDay().''; echo '
foreach($schedules as $schedule){ //開始日~終了日までを表示 if($Day->day >= date('d',strtotime($schedule['FeatureSchedule']['start_time'])) && $Day->day <= date('d',strtotime($schedule['FeatureSchedule']['end_time']))){ echo ' } } echo ' echo " | \n";
}
//週の表示
function week($schedules=null, $times=null){
$week = new Calendar_Week(date('Y',$times['from_time']), date('m',$times['from_time']),date('d',$times['from_time']), 0);
$week->build();
echo '
日 | 月 | 火 | 水 | 木 | 金 | 土 | ';
---|---|
'."\n"; | '.''.$Day->thisDay().''; echo '
foreach($schedules as $schedule){ //開始日~終了日までを表示 if($Day->day >= date('d',strtotime($schedule['FeatureSchedule']['start_time'])) && $Day->day <= date('d',strtotime($schedule['FeatureSchedule']['end_time']))){ echo ' } echo ' } } } echo " |
}
//日の表示
function day($schedules=null, $times=null){
}
function dayLink($time) {
$out = strftime('%m/%d', $time).__(strftime('(%a)', $time), true);
$out = $this->Html->link($out, array('action'=>'index', 'id'=>'day', date('Y/m/d',$time)));
return $out;
}
//***************************************************************
// 表示別ナビゲーション
//***************************************************************
function navi($controller, $scope, $current) {
$method = $scope.'_navi';
return $this->$method($controller, $current);
}
//月の場合
function month_navi($controller, $current) {
$url = $this->params['controller'].'/'.$this->params['action'];
list($year, $month, $day) = split('/',$current);
//先月
echo $this->Html->link('先月','/'.$url.'/month/'.date('Y/m/',mktime(0,0,0,$month-1,1,$year)),array('id'=>'btn','class'=>'lastmonth'));
//今月
echo $this->Html->link('今月','/'.$url.'/month/'.date('Y/m/'),array('id'=>'btn','class'=>'thismonth'));
//翌月
echo $this->Html->link('翌月','/'.$url.'/month/'.date('Y/m/',mktime(0,0,0,$month+1,1,$year)),array('id'=>'btn','class'=>'nextmonth'));
}
//週の場合
function week_navi($controller, $current) {
$url = $this->params['controller'].'/'.$this->params['action'];
list($year, $month, $day) = split('/', $current);
//先週
echo $this->Html->link('先週','/'.$url.'/week/'.date('Y/m/d', mktime(0,0,0,$month,$day-7,$year)),array('id'=>'btn','class'=>'lastweek'));
//今週
echo $this->Html->link('今週','/'.$url.'/week/'.date('Y/m/d'),array('id'=>'btn','class'=>'thisweek'));
//翌週
echo $this->Html->link('翌週','/'.$url.'/week/'.date('Y/m/d', mktime(0,0,0,$month,$day+7,$year)),array('id'=>'btn','class'=>'nextweek'));
}
//日の場合
function day_navi($controller, $current) {
$out = '
- ';
- %s ',
- %s ',
- %s ',
list($year, $month, $day) = split('/', $current);
$out .= sprintf('
$controller,
date('Y/m/d', mktime(0,0,0,$month,$day-1,$year)),
__('Previous day', true));
$out .= sprintf('
$controller,
date('Y/m/d'),
__('Today', true));
$out .= sprintf('
$controller,
date('Y/m/d', mktime(0,0,0,$month,$day+1,$year)),
__('Next day', true));
$out .= '
return $out;
}
}
?>
という感じで上手くいきました。
クラスとかがもっと理解できれば・・・。と思いますが、今度pearのpagerを使ったページ送りを試してみたいと思います。