2015-01-10 75 views
0

在這一刻我能夠顯示在選定的組合框中的人的名字,但我想將person_id存儲在數據庫中而不是人的名字。我怎樣才能做到這一點。如何將值傳遞給cakephp中的選定組合框?

控制器

公共功能指數(){

$this->Relation->save($this->request->data); 
    $this->loadModel('Profile'); 
    $person= $this->Profile->find('all'); 
    if($this->request->is('post')){ 
    } 
    $temp = array(); 
$temp1 = array(); 

    foreach($person as $person_name) 
    { 
     $temp[ $person_name['Profile']['id']] = $person_name['Profile']['id']; 
     $temp1[ $person_name['Profile']['first_name']] = $person_name['Profile']['first_name']; 

    } 
    $this->set('person_name', $temp); 
    $this->set('person_id', $temp1); 
} 

查看index.ctp

<?php echo $this->Form->input('person_id',array('multiple'=>true,'label'=>false,'type'=>'select','options'=>$person_name,'selected'=>$person_id)); ?> 

回答

1

在你看來index.ctp

$data = array_combine($person_id,$person_name); 

如果喲你打印$數據作爲pr($ data);

Array 
(
[54af7764-dcf8-4355-bcc7-3980c2f436a7] => sandeep 
[54af77bb-fe28-4634-a3f9-3980c2f436a7] => prakash 

) 

所以您選擇的組合框將

<?php echo $this->Form->input('person_id',array('label'=>false,'type'=>'select','options'=>$data)); ?> 
+0

我會嘗試這個 –

+0

非常感謝您普拉卡什,這個工作就像魅力。我從最後一天就爲此感到震驚,你在一分鐘內解決了這個問題,我非常感謝你的工作。再次非常感謝你。 –

相關問題