CakePHP 1.3 で日付フォームはヘルパーの datetime メソッドでとても簡単に作れる

日付のフォームがある場合は以下のようにして簡単に作ることができます。第一引数はフォームの名前、第二引数は日付の順番、第三引数は時間のフォーマットはどうするかで null を設定すれば時間自体を無しに出来ます。第四引数は配列で属性を設定します。
CakePHP: the rapid development php framework: Api : FormHelper

1
2
3
4
5
6
7
8
9
10
11
12
echo $form->datetime(
	'datetime',
	'YMD', 
	null,
	date('Y-m-d'),
	Array(
		'minYear' => 2010,
		'maxYear' => date('Y'),
		'separator' => ' / ',
		'monthNames' => false
	)
);

第四引数の属性について

第四引数の属性の説明を翻訳しておきます。

monthNames

If false, 2 digit numbers will be used instead of text. If a array, the given array will be used.

false を設定した場合、テキストの代わりに2桁の数字が使われます。配列の場合、指定された配列が使用されます。

separator

The contents of the string between select elements. Defaults to ‘-’

select 要素の間の文字列の内容。デフォルトは – (ハイフン) です。

minYear

The lowest year to use in the year select

年の選択で使える最小年数。

maxYear

The maximum year to use in the year select

年の選択で使える最大年数。

interval

The interval for the minutes select. Defaults to 1

分の選択の間隔。デフォルトは1です。

empty

If true, the empty select option is shown. If a string, that string is displayed as the empty element.

ture の場合、空の選択オプションが表示されます。文字列の場合、その文字列が空の要素として表示されます。

default

The default value to be used by the input. A value in $this->data matching the field name will override this value. If no default is provided time() will be used.

デフォルトの値は入力で使われます。$this->data の値が一致すればフィールド名をオーバライドします。デフォルト値は time() を提供されている場合に使われます。

コメント

コメントは受け付けていません。