开发者

Cakephp: Populate form options

I'm trying to populate a dropdown field inputbox with custom values:

echo $form->input('cities', array('div' => false, 'options' => $customCitie开发者_开发百科s));

in my controller:

public function find() {
  $this->Journey->recursive = 2;
  $ticities = $this->Journey->toACity->find('all');
  $customCities = array();
  foreach ($ticities as $tCities):
  foreach ($tCities as $ap):
   if(array_key_exists('id',$ap)){$customCities[]=$ap['name']);}
  endforeach;
  endforeach;
  $this->set('customCities', $customCities);
 ....

This allows me to set values for the dropdown box. But the dropdown box' entries' ids do not correspond to the Cities' real ids. -> All entries in the dropdown box have the default id (0,1,2,3...).

How can i set a custom value for each drop down entry. I tried:

$customCities[]=array($ap['id'],$ap['name']));

But this doesn't help.


change this part

$customCities[]=$ap['name'];

to

$customCities[$ap['id']]=$ap['name'];

finally looks like

if(array_key_exists('id',$ap)){$customCities[$ap['id']]=$ap['name'];}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜