如何在cake php中编写select选项并在选项中显示结果

时间:2015-01-03 09:53:55

标签: php

<select>
<?php $result=mysql_query('select id from contact');
while($row=$result){
$id = $row['id'];
?>
<option value='<?php echo $id; ?>'><?php echo $id; ?></option>
<?php } ?>
</select >

如何在cakephp中编写此选择框..

1 个答案:

答案 0 :(得分:2)

在控制器中进行列表查询(http://book.cakephp.org/2.0/en/models/retrieving-your-data.html):

$results = $this->Model->find('list', $options);

然后将其添加到视图中的表单元素(http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html):

$this->Form->input('Model.field', array('options' => $results));