HOME>WEBプログラム覚書>[CakePHP2.X]input select の「選択してください」的なやつ

[CakePHP2.X]input select の「選択してください」的なやつ

いちいちarray_merge()してましたが、FormHelper::input()のオプションで出来るんですね。

select.ctp

実行結果

  1. <?php
  2. echo $this->Form->input('langages', array(
  3.     'label'   => 'LL言語',
  4.     'type'    => 'select',
  5.     'options' => array(
  6.         'perl'   => 'Perl',
  7.         'php'    => 'PHP',
  8.         'python' => 'Python',
  9.         'ruby'   => 'Ruby',
  10.     ),
  11.     'div'     => false,
  12.     'empty'   => '選択してください'
  13. ));
  14. ?>

オプションの empty で設定することができます。

empty - String or boolean to enable empty select box options.

FormHelper::input()

これは知らなかった。

投稿日 2013年12月26日 22:59
カテゴリ PHP
タグ CakePHP
トラックバック URL http://www.kantenna.com/cgi-bin/mt504/mt-tb.cgi/1344

コメント

コメントする
Name
Email Address
URL