我們的小組創建了一個數據庫供顧客參加一個有很多實體的事件(預訂)。Cakephp:將參數或數據傳遞給另一個頁面
我們有三個表:顧客,預訂,booking_patron(連接表)。
我們希望在booking_patron的視圖(add.ctp和add2.ctp)中創建2個頁面。
Page add.ctp有一個下拉框,其中列出了預訂ID和提交按鈕。 頁面add2.ctp應顯示我們之前選擇的預訂ID(在add.ctp中)。同樣在add2.ctp中,我們確實創建了一個函數,用戶可以創建一個贊助人並將該贊助人分配給預訂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 your information. Please, try again.'));
}
}
}
的問題是:我們不知道如何從add.ctp到add2.ctp獲得預訂ID。 目前,我們使用一個下拉框來列出add2.ctp中的預訂ID來選擇預訂;我們希望將其更改爲出現add.ctp預訂ID的靜態文本字段。
我們還有一個函數可以在add2.ctp中創建一個新的顧客。我們希望新的靠山從add.ctp分配到所選擇的預約ID
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-> Session-> write('booking_id',$ id);' – noslone
ty for the solution,but I just not get it(im new)。我應該在哪裏添加此代碼?是它add.ctp或添加功能在控制器 –
在這種情況下,你應該閱讀[文檔](http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#sessions) – noslone