Reputation: 13
Hello helper i am begginer in cake i have a issue i have a select box which is like this.
<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>
but i need that value should be same like option. like option value Room PG Rent, Placement... not like 0 1 ... here is my controller
$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);
here is my view.
<?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
));
?>
Upvotes: 0
Views: 106
Reputation: 38
To achieve this the $cities array must be like this:
array(
'Room PG Rent' => 'Room PG Rent',
'Placement' => 'Placement',
'Movers and Packers' => 'Movers and Packers'
)
To convert the $cities array to this format do:
$cities = array_combine($cities, $cities);
Upvotes: 1