<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中编写此选择框..
答案 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));