cakephp动态选择框问题

时间:2015-01-15 06:42:57

标签: cakephp

Hello helper我是蛋糕中的begginer我有一个问题我有一个选择框就是这样。

<select name="services" id="services" class="form-control">
<option value="0">Room PG Rent</option>
<option value="1">Placement</option>
<option value="2">Restaurant</option>
<option value="3">Movers and Packers</option>
</select>

但我需要该值应该与选项相同。喜欢选项价值房间PG租金,安置...不喜欢0 1 ... 这是我的控制器

$this->loadModel("Services");
$agetservices = $this->Services->getservices();
$this->set(compact('agetservices'));
for($i=0;$i<count($agetservices);$i++)
{
$agetservices[$i]=$agetservices[$i]['Services']['name'];
}
$this->set('agetservices', $agetservices);

这是我的观点。

<?php
    echo $this->Form->input('cities', array(
        'type' => 'select',
        'name' => 'cities',
        'id'=>'cities',
        'label' => 'City <span class="required small">(Required)</span>',
        'class'=>'form-control',
        'placeholder'=>'Search For Anything Anywhere in Jaipur',
        'options' => $agetservices,
        'empty'   => false
    ));
?>  

1 个答案:

答案 0 :(得分:1)

要实现这一点,$ cities数组必须是这样的:

array(
    'Room PG Rent' => 'Room PG Rent',
    'Placement' => 'Placement',
    'Movers and Packers' => 'Movers and Packers'
)

要将$ cities数组转换为此格式,请执行以下操作:

$cities = array_combine($cities, $cities);