LoginSignup
11
12

More than 5 years have passed since last update.

CakePHP3の日付セレクトボックスの日本語化

Posted at

CakePHP3の日付セレクトボックスの日本語化はCakePHP2の方法ではうまくいかなかったのでメモです。

例はBoostrap3を使ってます。

// 日本語対応(YYYY年MM月DD日 HH時mm分)
$this->Form->templates([
    'dateWidget' => '<ul class="list-inline"><li class="year">{{year}} 年</li><li class="month"> {{month}} 月 </li><li class="day"> {{day}} 日 </li><li class="hour"> {{hour}} 時 </li><li class="minute"> {{minute}} 分 </li></ul>'
]);

echo $this->Form->input('start_datetime', array(
                                     'type' => 'datetime',
                                     'label' => '開始日時',
                                     'dateFormat' => 'YMD',
                                     'monthNames' => false,
                                     'separator' => '/',
                                     'minYear' => date('Y'),
                                     'maxYear' => date('Y')+1,
                                     'default' => date('Y-m-d')
                                ));

Creating DateTime Inputs

11
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
12