Cakephp: pass parameter or data to another page -


our group create database patron attend event (booking) has lots of entities.

we have 3 tables: patron, booking, booking_patron (join table).

we want create 2 pages in view (add.ctp , add2.ctp) of booking_patron.

page add.ctp has drop down box lists booking id , submit button. page add2.ctp should appear booking id chose before (in add.ctp). in add2.ctp, did make function user can create patron , assign patron booking id.

bookingspatronscontroller.php

public function add() {     $bookings = $this->bookingspatron->booking->find('list');     $this->set(compact('bookings', 'patrons')); } public function add2($booking_id = null) {      $patrons = $this->bookingspatron->patron->find('list');     $bookings = $this->bookingspatron->booking->find('list');     $this->set(compact('bookings', 'patrons'));     if ($this->request->is('post')) {         $this->bookingspatron->patron->create();          if ($this->bookingspatron->patron->save($this->request->data)) {             $this->session->setflash("sign in successful");              $this->bookingspatron->create();              $this->session->setflash(__('well.... done'));              $this->redirect(array('action' => 'add3'));         } else {             $this->session->setflash(__('we can not add information. please, try again.'));         }     } } 

the problem is: don't know how booking id add.ctp add2.ctp. @ moment, use drop down box list booking id in add2.ctp choose booking; want change static text field appears booking id add.ctp.

we have function can create new patron in add2.ctp. want assign new patron chosen booking id add.ctp

add.ctp

<?php echo $this->form->input('booking.booking_id');?> <?php echo $this->html->link(__('create'), array('action' => 'add3')); ?> 

add2.ctp

<?php echo $this->form->create('bookingspatron'); ?> <fieldset> <?php echo $this->form->input('booking.booking_id');?> <table cellpadding="3" cellspacing="3"> <tr>     <td class="heading">name: </td>     <td><?php echo $this->form->input('patron.patrons_name', array('label' => '', 'div' => 'formlabel'));?></td>     <td></td><td></td>     <td class="heading">e-mail: </td>     <td><?php echo $this->form->input('patron.patrons_email', array('label' => '', 'div' => 'formlabel'));?></td> </tr> <tr>     <td class="heading">age: </td>     <td><?php echo $this->form->input('patron.patrons_age', array('label' => '', 'div' => 'formlabel'));?></td>     <td></td><td></td>             <td class="heading">company: </td>     <td><?php echo $this->form->input('patron.patrons_company', array('label' => '', 'div' => 'formlabel'));?></td> </tr> <tr>     <td class="heading">postcode: </td>     <td><?php echo $this->form->input('patron.patrons_postcode', array('label' => '', 'div' => 'formlabel'));?></td>     <td></td><td></td>             <td class="heading">gender: </td>     <td><?php echo $this->form->input('patron.patrons_gender', array('label' => '', 'div' => 'formlabel', 'type' => 'select', 'options' => array('male' => 'male', 'female' => 'female')));?></td> </tr> <tr>     <td colspan="2">ph: 1300 7 34726</td>     <td colspan="3"></td>     <td><?php  echo $this->form->submit('submit', array('class' => 'classsubmitbutton', 'title' => 'sbumit')); ?></td> </tr> </table>  </fieldset> 

this should work

public function add() {     if ($this->request->is('post')) {          $this->session->write('booking_id', $this->request->data['booking']['booking_id']);          $this->redirect(array('action' => 'add2')); // line added     }     $bookings = $this->bookingspatron->booking->find('list');      $this->set(compact('bookings', 'patrons')); } 

and retreive id use in add2() function

$booking_id = $this->session->read('booking_id'); 

update

edit add.ctp -- needs form, not link, otherwise don't submit booking id

<?php      echo $this->form->create('booking');     echo $this->form->input('booking.booking_id');     echo $this->form->end(__('create')); ?> 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -