开发者

cakePHP: $this->Form->input() - How to set a select default option

开发者 https://www.devze.com 2023-03-11 08:12 出处:网络
In my view I have: echo $this->Form->input(\'category_parent_id\'); and it outputs: <option value=\"1\">category name 1</option>

In my view I have:

echo $this->Form->input('category_parent_id');

and it outputs:

<option value="1">category name 1</option>
<option value="2">category name 2</option>
...

but how do I tell it input() that I want a default option like so?:

<option value="">select a ca开发者_运维百科tegory</option>
<option value="1">category name 1</option>
<option value="2">category name 2</option>
...

nvm, found it:

echo $this->Form->input('category_parent_id', array('empty' => 'Select a parent category'));


Your question is a little vague, but you can do the following to select a default option...

echo $this->Form->input('category_parent_id', array('default' => 'id_of_default_val'));

EDIT

Per your edit, to include an empty default option, do this as documented in the CakePHP Form Helper...

echo $this->Form->input('category_parent_id', array('empty' => 'choose one'));
0

精彩评论

暂无评论...
验证码 换一张
取 消