Jump to content
Larry Ullman's Book Forums

Yii Booking Form


weno
 Share

Recommended Posts

I have three tables in my database booking, bookingrooms, room and the bookingrooms is the link table resolving many to many.

 

CRUD has created forms for booking and room, but the booking form is too simple and does not include the bookingrooms section that I want in the form.

 

How do I put this area onto the booking form? I presume it's something to do with multiple models and custom forms.

 

Link to comment
Share on other sites

You can't put the MANY_MANY relationship into Gii, you don't actually need to create a model for the intermediary table bookingrooms. All you are required to do is create a MANY_MANY relation in the Booking model(). You could also create the relation in the Room model if you have to. But here is what the relation will look like in your Booking model():

 

public function relations()
    {
        return array(
            'bookingRoom'=>array(self::MANY_MANY,'Room','booking_rooms(booking_id,room_id)'),
       
        );
    }

Link to comment
Share on other sites

Hi, I have run into another problem.

 

I have begun implementing the master detail form. In the create.php form I have duplicated rows(HTML and fields) which are for user input, but this causes the highlighted fields(that have been chosen in the last form submission) on the webpage to duplicate... if I choose a value in the first row it automatically chooses the same in the second row. I use two models - both of them are passed to the form.

<?php
/* @var $this BookingController */
/* @var $model Booking */

$this->breadcrumbs=array(
        'Bookings'=>array('index'),
        'Create',
);

$this->menu=array(
        array('label'=>'List Booking', 'url'=>array('index')),
        array('label'=>'Manage Booking', 'url'=>array('admin')),
);
?>

<h1>Create Booking</h1>

<?php //$this->renderPartial('_form', array('model'=>$model)); ?>

<?php
/* @var $this BookingController */
/* @var $model Booking */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'booking-form',
        // Please note: When you enable ajax validation, make sure the corresponding
        // controller action is handling ajax validation correctly.
        // There is a call to performAjaxValidation() commented in generated controller code.
        // See class documentation of CActiveForm for details on this.
        'enableAjaxValidation'=>false,
)); ?>

        <p class="note">Fields with <span class="required">*</span> are required.</p>

        <?php echo $form->errorSummary($model); ?>

        <div class="row">
                <?php echo $form->labelEx($model,'Id'); ?>
                <?php echo $form->textField($model,'Id'); ?>
                <?php echo $form->error($model,'Id'); ?>
        </div>

        <div class="row">
                <?php echo $form->labelEx($model,'customerId'); ?>
                <?php echo $form->textField($model,'customerId'); ?>
                <?php echo $form->error($model,'customerId'); ?>
        </div>

        <div class="row">
                <?php echo $form->labelEx($model,'date'); ?>
                <?php echo $form->textField($model,'date'); ?>
                <?php echo $form->error($model,'date'); ?>
        </div>
                    
        
        <div>
        <?php echo $form->labelEx($BookingRoom,'Room No'); ?>
        <?php echo $form->dropDownList($BookingRoom, 'roomId', CHtml::listData(
        Room::model()->findAll(), 'id', 'id'), array('single'=>'single', 'size'=>5)
        ); ?>
        <?php echo $form->error($BookingRoom,'roomId'); ?>
        </div>
        
        <div>
                <?php echo $form->labelEx($BookingRoom,'startDate'); ?>
                <?php echo $form->textField($BookingRoom,'startDate'); ?>
                <?php echo $form->error($BookingRoom,'startDate'); ?>
        </div>
        <div>
                <?php echo $form->labelEx($BookingRoom,'endDate'); ?>
                <?php echo $form->textField($BookingRoom,'endDate'); ?>
                <?php echo $form->error($BookingRoom,'endDate'); ?>
        </div>
        
        <div>
        <?php echo $form->labelEx($BookingRoom,'adults'); ?>
        <?php echo $form->dropDownList($BookingRoom, 'adults', array('1'=>'1', 
                                                                     '2'=>'2', 
                                                                     '3'=>'3', 
                                                                     '4'=>'4',
                                                                     '5'=>'5'), array('single'=>'single', 'size'=>5)
        ); ?>
        <?php echo $form->error($BookingRoom,'adults'); ?>
        </div>
        
                <div>
        <?php echo $form->labelEx($BookingRoom,'children'); ?>
        <?php echo $form->dropDownList($BookingRoom, 'children', array('1'=>'1', 
                                                                     '2'=>'2', 
                                                                     '3'=>'3', 
                                                                     '4'=>'4',
                                                                     '5'=>'5'), array('single'=>'single', 'size'=>5)
        ); ?>
        <?php echo $form->error($BookingRoom,'children'); ?>
        </div>
        
        
        
        
        
               <div>
        <?php echo $form->labelEx($BookingRoom,'Room No'); ?>
        <?php echo $form->dropDownList($BookingRoom, 'roomId', CHtml::listData(
        Room::model()->findAll(), 'id', 'id'), array('single'=>'single', 'size'=>5)
        ); ?>
        <?php echo $form->error($BookingRoom,'roomId'); ?>
        </div>
        
        <div>
                <?php echo $form->labelEx($BookingRoom,'startDate'); ?>
                <?php echo $form->textField($BookingRoom,'startDate'); ?>
                <?php echo $form->error($BookingRoom,'startDate'); ?>
        </div>
        <div>
                <?php echo $form->labelEx($BookingRoom,'endDate'); ?>
                <?php echo $form->textField($BookingRoom,'endDate'); ?>
                <?php echo $form->error($BookingRoom,'endDate'); ?>
        </div>
        
        <div>
        <?php echo $form->labelEx($BookingRoom,'adults'); ?>
        <?php echo $form->dropDownList($BookingRoom, 'adults', array('1'=>'1', 
                                                                     '2'=>'2', 
                                                                     '3'=>'3', 
                                                                     '4'=>'4',
                                                                     '5'=>'5'), array('single'=>'single', 'size'=>5)
        ); ?>
        <?php echo $form->error($BookingRoom,'adults'); ?>
        </div>
        
                <div>
        <?php echo $form->labelEx($BookingRoom,'children'); ?>
        <?php echo $form->dropDownList($BookingRoom, 'children', array('1'=>'1', 
                                                                     '2'=>'2', 
                                                                     '3'=>'3', 
                                                                     '4'=>'4',
                                                                     '5'=>'5'), array('single'=>'single', 'size'=>5)
        ); ?>
        <?php echo $form->error($BookingRoom,'children'); ?>
        </div>
        
        
        
        
        
        <div class="row buttons">
                <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
        </div>

<?php $this->endWidget(); ?>

</div><!-- form -->
  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...