has and belongs to many - Cakephp HABTM: View generating drop down instead of multi value selectbox -
i trying work habtm association between profiles , qualifications tables.
model: profile.php
app::uses('appmodel', 'model'); class profile extends appmodel { public $hasandbelongstomany = array( 'qualification' => array( 'classname' => 'qualification', 'jointable' => 'profile_qualifications', 'foreignkey' => 'profile_id', 'associationforeignkey' => 'qualification_id', 'unique' => 'keepexisting' ) ); }
model: qualification.php
app::uses('appmodel', 'model'); class qualification extends appmodel { public $hasandbelongstomany = array( 'profile' => array( 'classname' => 'profile', 'jointable' => 'profile_qualifications', 'foreignkey' => 'qualification_id', 'associationforeignkey' => 'profile_id', 'unique' => 'keepexisting', ) ); }
controller: profilescontroller.php
app::uses('appcontroller', 'controller'); class profilescontroller extends appcontroller { public function edit() { $this->profile->id = $this->auth->user('profile_id'); if ($this->request->is('post') || $this->request->is('put')) { if ($this->profile->save($this->request->data)) { $this->session->setflash(__('the profile has been saved')); $this->redirect(array('action' => 'view')); } else { $this->session->setflash(__('the profile not saved. please, try again.')); } } else { $this->request->data = $this->profile->read(null, $this->auth->user('profile_id')); } $salutations = $this->profile->salutation->find('list', array('fields' => array('salutation.id', 'salutation.abbr_name'))); $qualifications = $this->profile->qualification->find('list', array('fields' => array('qualification.id', 'qualification.abbr_name'))); $this->set(compact('salutations', 'qualifications')); } }
vew: edit.ctp
<div class="profiles form"> <?php echo $this->form->create('profile'); ?> <fieldset> <legend><?php echo __('my profile'); ?></legend> <?php echo $this->form->input('salutation_id'); echo $this->form->input('first_name'); echo $this->form->input('middle_name'); echo $this->form->input('last_name'); echo $this->form->input('qualification'); /* gives drop down not multi select */ echo $this->form->input('bio'); echo $this->form->input('email'); echo $this->form->input('mobile'); echo $this->form->input('phone'); ?> </fieldset> <?php echo $this->form->end(__('submit')); ?> </div>
the edit view generated contains drop down select single value @ time qualifications attribute.
i want know how can generate view multi value selection box qualifications ? moreover, mistake in code right ?
change
echo $this->form->input('qualification');
to
echo $this->form->input('qualification', array( 'multiple' => true ));
the cakephp manual has more information on form helper input options.
Comments
Post a Comment