LoginSignup
1
3

More than 5 years have passed since last update.

CakePHP2の日付や時間のセレクトボックスにseparatorを指定する

Posted at

screenshot001.png
みたいな感じで表示したいとき(ボックス間の年月日のこと)

やるべきこと

  1. FormHelperの編集
  2. Viewの実際に表示するとこにSeparatorオプションの指定

FormHelperの編集

lib/Cake/View/Helper/FormHelper.phpの下らへん(僕の場合は2602行目)に

$opt = implode($separator, $selects);

ってのがある。
それをコメントアウトして、以下を挿入

    $opt = '';
    if (is_array($separator)) {
        $i = 0;
        foreach($selects as $select) {
            $opt .= $select . $separator[$i];
            $i++;
        }
    } else {
        $opt = implode($separator, $selects);
    }

Viewの実際表示するとこにSeparatorオプションの指定

こんな感じ(見た目良くするために関係ないこと書いてるけど無視してください※bootstrap使ってます)

echo $this->Form->input('hogehoge',array('label'=>false,'placeholder'=>'取得日','dateFormat'=>'YMD','monthNames'=>false,'separator' => array(' 年 ', ' 月 ', ' 日 '),'class'=>'form-control','style'=>'width:70px'))

すると、こんな感じの表示になります

screenshot001.png

1
3
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
1
3