Cbuttoncolumn Url

Why is is that I can echo the correct value when echoing $tempSeats but when I try and place the variable in the CButtonColumn ‘url’ field it does not display anything? I have tried numerous solutions to get the variable to show up in the url with no success. Am I missing something easy?


<?php 


$tempSeats = Yii::app()->getRequest()->getQuery('adult-list');


echo $tempSeats;


$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'=>'$this->grid->controller->createUrl("/bookings/createBooking/flightID/$data->flightID/", array("tempSeats"=>$tempSeats))',

        ),

    ),

),

	),

)); ?>

Hi,

try this


'url'=>'$this->grid->controller->createUrl("/bookings/createBooking/flightID/$data->flightID/", array(\'tempSeats\'=>$tempSeats))'

Thanks for the reply. I am still only seeing /bookings/createBooking/flightID/$data->flightID/tempSeats/

the $tempSeats value is not being placed in the URL still.

This won’t change anything, it just changes double quote to single quote which in PHP it means the same (in this case).

I think the problem is, the OP passed that statement in a string, it should be:


'url' => $this->grid->controller->createUrl("/bookings/createBooking/flightID/$data->flightID/", array('tempSeats'=>$tempSeats))

see I removed the outer quotes?

I removed the outer quotes like suggested and now I receive this error:

Property "FlightsController.grid" is not defined.

Any ideas?

That’s not how createUrl() works. The first parameter is the route (controller/action), the second is an array of GET variables. Try this:


'url'=>'Yii::app()->createUrl("bookings/createBooking", array("flightID"=>$data->flightID, "tempSeats"=>$tempSeats))',

Still empty, I even tried to do $data->tempSeats and it shows zero for every entry. However when I use $data->tempSeats as a column it works fine:


array(

			'header'=>'Temp Seats',

			'value'=>$data->tempSeats,

			'id'=>'tempSeats',

			),

I can’t figure out why it will display correctly in the column but not the URL.

you can try the


"tempSeats" => "{$data->tempSeats}"


'url'=>'Yii::app()->createUrl("bookings/createBooking", array("flightID"=>$data->flightID, "tempSeats" => "{$data->tempSeats}"))',

Still showing zero, this has me stumped.

Ok finally got it to work using:

‘url’=>‘Yii::app()->createUrl("bookings/createBooking/flightID/$data->flightID/tempSeats/’.$data->tempSeats.’")’,

Thanks for everyones help.