如何在CakePHP中加载选择框

时间:2013-12-16 06:05:26

标签: php cakephp-2.0

我正在尝试使用cakephp中的某些数据库值填充选择框。我从数据库查询得到的数组如下,

Array ( 
[0] => Array ( [mst_division] => Array ( [mstDivisionID] => 1 [Division] => Sydney ) )
[1] => Array ( [mst_division] => Array ( [mstDivisionID] => 2 [Division] => Tokyo 3 ) ) 
[2] => Array ( [mst_division] => Array ( [mstDivisionID] => 3 [Division] => Osaka 9 ) ) 
)

我对如何将其加载到选择框感到困惑。我的PHP代码如下所示,

echo $this->Form->input('Division', array(
                        'type' => 'select',
                        'options' => $divisions,
                        'selected' => 2)
                       );

我的html代码也显示在下面,

<div class="input select"><label for="MemberDivision">Division</label><select      name="data[Member][Division]" id="MemberDivision">
</optgroup>
<option value="Division">Sydney</option>
<optgroup label="mst_division">
<optgroup label="1">
</optgroup>
<option value="Division">Tokyo 3</option>
<optgroup label="mst_division">
</optgroup>
<optgroup label="2">
</optgroup>
<option value="Division">Osaka 9</option>
<option value="mstDivisionID">3</option>
<optgroup label="mst_division">
</optgroup>
</select>
</div>

1 个答案:

答案 0 :(得分:3)

$this->set('divisions',$this->Model->find('list'));

尝试一下,我希望它会起作用。