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?:
但是如何告诉它input()我想要一个默认选项呢?:
<option value="">select a category</option>
<option value="1">category name 1</option>
<option value="2">category name 2</option>
...
nvm, found it:
nvm,发现它:
echo $this->Form->input('category_parent_id', array('empty' => 'Select a parent category'));
1 个解决方案
#1
15
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...
根据您的编辑,要包含一个空的默认选项,请按照CakePHP表单助手中的说明执行此操作...
echo $this->Form->input('category_parent_id', array('empty' => 'choose one'));
#1
15
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...
根据您的编辑,要包含一个空的默认选项,请按照CakePHP表单助手中的说明执行此操作...
echo $this->Form->input('category_parent_id', array('empty' => 'choose one'));