ms122r
(Ms122r2)
August 12, 2013, 1:01am
1
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))'
ms122r
(Ms122r2)
August 12, 2013, 1:33pm
3
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.
explorer
(Xdim11)
August 12, 2013, 5:24pm
4
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?
ms122r
(Ms122r2)
August 12, 2013, 5:30pm
5
I removed the outer quotes like suggested and now I receive this error:
Property "FlightsController.grid" is not defined.
Any ideas?
explorer:
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?
Tsunami
(Erik)
August 12, 2013, 5:46pm
6
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))',
ms122r
(Ms122r2)
August 12, 2013, 6:16pm
7
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.
Tsunami:
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))',
you can try the
"tempSeats" => "{$data->tempSeats}"
'url'=>'Yii::app()->createUrl("bookings/createBooking", array("flightID"=>$data->flightID, "tempSeats" => "{$data->tempSeats}"))',
ms122r
(Ms122r2)
August 13, 2013, 1:21pm
9
Still showing zero, this has me stumped.
you can try the
"tempSeats" => "{$data->tempSeats}"
'url'=>'Yii::app()->createUrl("bookings/createBooking", array("flightID"=>$data->flightID, "tempSeats" => "{$data->tempSeats}"))',
ms122r
(Ms122r2)
August 13, 2013, 1:35pm
10
Ok finally got it to work using:
‘url’=>‘Yii::app()->createUrl("bookings/createBooking/flightID/$data->flightID/tempSeats/’.$data->tempSeats.’")’,
Thanks for everyones help.