0

検索フォームからの入力に基づいて、変数「tempSeats」の値を一時的に更新したいと考えています。検索フォームは、選択したフライトと顧客 ID に基づいてリンクを生成するために使用する CGridView を更新します。また、検索フォームから生成された URL に「tempSeats」の数を追加したいと思います。

これまでのところ、問題なく顧客 ID とフライト ID を渡すことができました。検索フォームが送信されたときに一時シートを更新できないようです。渡される値は常に 0 です。

どんな助けでも大歓迎です。

ここに私の検索フォームがあります:

<?php $form=$this->beginWidget('CActiveForm', array(
    'action'=>Yii::app()->createUrl($this->route),
    'method'=>'get',
)); ?>
    <span style="font-size:18px;font-weight:bold;">Route: </span>
    <div class="row">
              <?php echo CHtml::dropDownList(
     'departLocation',// for "name" attribute of <select> html tag,
                // this also becomes the "id" attribute, incase you don't specify
                // it explicitly in the htmlOptions array
     '', // the option element that is to be selected by default
     CHtml::listData( // listData helps in generating the data for <option> tags
        Airport::model()->findAll(), // a list of model objects. This parameter
              // can also be an array of associative arrays
              // (e.g. results of CDbCommand::queryAll).
        'airportName', // the "value" attribute of the <option> tags, 
              // here will be populated with id column values from program table 
        'airportName' // the display text of the <option> tag,
              // here will be populated with program_name column values from table
     ),
     array('empty'=>'From') // the htmlOptions array, whose values will be
              // generated as html attributes of <select> and <option> tags
);?>
        <?php echo CHtml::dropDownList(
     'arrivalLocation',
     'empty',
     CHtml::listData(
        Airport::model()->findAll(),
        'airportName',
        'airportName'
     ),
     array('empty'=>'To')
);?>
    </div>
    <hr>
    <span style="font-size:18px;font-weight:bold;">Dates:</span>
    <div class="row">
        Departing:
        <?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
    'model' => Flights::model(),
    'attribute' => 'departDay', 
    'value'=>Flights::model()->departDay,
    'options' => array(
        'numberOfMonths'=>1,
        'showButtonPanel'=>true,
        'dateFormat' => 'yy-mm-dd',),
    'htmlOptions' => array(
        'class' => 'date',
         'value' => date("Y-m-d")),
));
?>
<?php echo $form->error($model,'date_from'); ?>
    </div>
    <hr>
    <span style="font-size:18px;font-weight:bold;">Travelers:</span>
    <div class="row">

              <?php echo CHtml::activeDropDownList($model,'tempSeats',array('1' => '1 Adult', '2' => '2 Adults', '3' => '3 Adults', '4' => '4 Adults', '5' => '5 Adults', '6' => '6 Adults', '7' => '7 Adults', '8' => '8 Adults', '9' => '9 Adults', '10' => '10 Adults', '11' => '11 Adults', '12' => '12 Adults', '13' => '13 Adults', '14' => '14 Adults', '15' => '15 Adults', '16' => '16 Adults', '17' => '17 Adults', '18' => '18 Adults', '19' => '19 Adults', '20' => '20 Adults',)
              );?>



        <?php echo CHtml::dropDownList('infant-list', $select, 
              array('0' => '0 Lap Infants (under 2)','1' => '1 Lap Infant',)
              ); ?>
              <?php echo CHtml::dropDownList(
     'dogSeats',
     'empty',
     CHtml::listData(
        Flights::model()->findAll(),
        'allowDogs',
        'allowDogs'
     ),
     array('empty'=>'0 Dogs')
);?>
    </div>

    <div class="row buttons">
        <?php echo CHtml::submitButton('Submit'); ?>
    </div>
    </div>

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

検索フォームが表示されるビューは次のとおりです。

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

<?php

Yii::app()->clientScript->registerScript('searchFlights', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('my-list', {
data: $(this).serialize()
});

return false;
});
");

?>



<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'my-list',
    'dataProvider'=>$model->searchFlights(),
    'filter'=>$model,
    'columns'=>array(
        'departTime',
        'departLocation',
        'departDay',
        'arrivalTime',
        'arrivalLocation',
        'price',
        'totalSeats',
        array(
            'header'=>'Seats',
            'value'=>'0',
            'id'=>'adultSeats',
            ),
        /*

        'allowDogs',
        */
        array(
    'class'=>'CButtonColumn',
    'template'=>'{book}',
    'buttons'=>array
    (
        'book' => array
        (
            'label'=>'Book Now',
            //'url'=>'CHtml::encode($data->flightID)',
            //'url'=>'$this->grid->controller->createUrl("/bookings/createBooking", array("flightID"=>$data->flightID))',
            'url'=>'$this->grid->controller->createUrl("/bookings/createBooking/flightID/$data->flightID/tempSeats/$data->tempSeats")',
        ),
    ),
),
    ),
)); ?>

私のフライトモデルでの検索の関数は次のとおりです。

public function searchFlights()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('flightID',$this->flightID);
        $criteria->compare('flightName',$this->flightName,true);
        $criteria->compare('departDay',$this->departDay,true);
        $criteria->compare('departTime',$this->departTime,true);
        $criteria->compare('departLocation',$this->departLocation,true);
        $criteria->compare('arrivalDay',$this->arrivalDay,true);
        $criteria->compare('arrivalTime',$this->arrivalTime,true);
        $criteria->compare('arrivalLocation',$this->arrivalLocation,true);
        $criteria->compare('totalSeats',$this->totalSeats);
        $criteria->compare('price',$this->price,true);
        $criteria->compare('allowDogs',$this->allowDogs);
        $criteria->compare('infantSeats',$this->infantSeats);
        $criteria->compare('dogSeats',$this->dogSeats);
        $criteria->compare('tempSeats',$this->totalSeats);

そして、これが Flight Controller からの私の actionIndex です。

/**
     * Lists all models.
     */
    public function actionIndex()
    {
        $model = new Flights('search');
$model->unsetAttributes(); // clear any default values
if (isset($_GET['Flights']))
$model->attributes = $_GET['Flights'];

$dataProvider=new CActiveDataProvider('Flights');
$this->render('index', array(
'model' => $model,
'dataProvider'=>$dataProvider,
));
    }
4

0 に答える 0