开发者

cakePHP: $this->Form->input() - How to set a select default 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜