2015-01-15 84 views
0

你好幫手我是在蛋糕begginer我有一個問題,我有一個選擇框是這樣的。cakephp動態選擇框問題

<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

爲了實現這一目標,$城市數組必須是這樣的:

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

到$城市數組轉換爲這種格式做:

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

非常感謝的人現在的工作很好。 – ggutigod