0

私たちのグループは、多数のエンティティを持つイベント (予約) に参加する常連客用のデータベースを作成します。

3 つのテーブルがあります。patron、booking、booking_patron (結合テーブル) です。

booking_patron のビュー (add.ctp と add2.ctp) に 2 つのページを作成します。

ページ add.ctp には、予約 ID と送信ボタンを一覧表示するドロップダウン ボックスがあります。add2.ctp ページには、前に (add.ctp で) 選択した予約 ID が表示されます。また、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.'));
        }
    }
}

問題は、予約 ID を add.ctp から add2.ctp に取得する方法がわからないことです。現時点では、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>
4

1 に答える 1

0

これはうまくいくはずです

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'));
}

ID を取得するには、これを add2() 関数で使用します

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

アップデート

add.ctp を編集 -- これは単なるリンクではなく、フォームである必要があります。それ以外の場合は、予約 ID を送信しません。

<?php 
    echo $this->Form->create('Booking');
    echo $this->Form->input('Booking.booking_id');
    echo $this->Form->end(__('Create'));
?>
于 2013-05-21T11:28:56.893 に答える