swisscheese
(Swisscheese2122)
1
I am trying to pass a variable from an ajaxLink into my controller but my controller is not getting the variable.
//view
$ids = Yii::app()->storedData->getIds();
foreach($ids as $id) {
echo 'ID '.$id .'<br />';
echo CHtml::ajaxLink(
'remove',
array('/storedInfo/remove'),
array(
'data' => array('removeItem' => $id),
));
}
//controller
public function actionRemove() {
var_dump($_GET['removeItem']); // RETURNS string(0) ""
die();
}
seenivasan
(Chellamnivas)
2
Dear Friend
The following is working
VIEW(five.php)
for($i=1;$i<10;$i++)
echo CHtml::ajaxLink("click".$i,array("test/seven"),array(
"data"=>array("id"=>$i),
"success"=>'js:function(d){console.log(d)}'
))
CONTROLLER
public function actionSeven(){
if(isset($_GET['id']))
{ echo $_GET['id'];
Yii::app()->end();
}
$this->render('five');
}
swisscheese
(Swisscheese2122)
3
Thanks but your code is basically what I have. Unfortunately something is causing mine not to work.
Have you tried removing the preceeding slash in array(’/storedInfo/remove’) to array(‘storedInfo/remove’).
Use FireBug or Google Chrome’s Inspect Element to see what’s happening. That’ll give you a better idea.
swisscheese
(Swisscheese2122)
5
With help from SO, I used settype to change the php type from object to string.