$form->datetimeの改造 | suzukiのCakePHPブログ

$form->datetimeの改造

cake/lib/views/helpers/form.phpを
app/views/helpers/form.phpにコピー

function __generateOptionsの修正

   case 'month':
    for ($i = 1; $i <= 12; $i++) {
     #$data[sprintf("%02s", $i)] = strftime("%B", mktime(1, 1, 1, $i, 1, 1999));
     ↓
     $data[sprintf("%02s", $i)] = strftime("%m", mktime(1,1,1,$i,1,1999));
    }
   break;

これで、$form->datetimeが出力する月リストが数字になる

function dateTimeの修正

  #$attributes = array_merge(array('minYear' => null, 'maxYear' => null, 'separator' => '-'), (array)$attributes);
  ↓
  $attributes = array_merge(array('minYear' => null, 'maxYear' => null, 'separator' => null), (array)$attributes);
  ※デフォルトを"-"からnullへ

下のほう

   #$opt = implode($separator, $selects);
   ↓
   if (!isset($separator)) {
    $glue = array("年", "月", "日", "時", "分", "秒");
    $i = 0;
    foreach ($selects as $select) {
     $opt .= $select.$glue[$i];
     $i++;
    }
   } else {
    $opt = implode($separator, $selects);
   }

これで、セパレーターがnullなら年月日で並ぶようになる