Reputation: 141
At this moment i am able to display the names of the person in selected combobox, but i want to store the person_id in database instead of person's name . How can i achieve this.
Controller
public function index() {
$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);
}
View index.ctp
<?php echo $this->Form->input('person_id',array('multiple'=>true,'label'=>false,'type'=>'select','options'=>$person_name,'selected'=>$person_id)); ?>
Upvotes: 0
Views: 494
Reputation:
In your view index.ctp
$data = array_combine($person_id,$person_name);
if you print that $data as pr($data);
Array
(
[54af7764-dcf8-4355-bcc7-3980c2f436a7] => sandeep
[54af77bb-fe28-4634-a3f9-3980c2f436a7] => prakash
)
so your selected combo box will be
<?php echo $this->Form->input('person_id',array('label'=>false,'type'=>'select','options'=>$data)); ?>
Upvotes: 1