Hi all,
I have a CButtonColumn column in my CGridView. I’m trying to add a custom button/link(that makes an ajax call) as the header.
The button works fine when it’s not in the header, but when i have it in the header for some reason 2 ajax calls are made instead of one(i get two alert pop-ups, one that i created and one with an error).
My custom action called by my button checks to make sure if the request is a POST request or not(will through an exception if not) then updates some content.
Here’s my CGridView:
array(
'class'=>'CButtonColumn',
'header'=>"$model->payallbutton",
'htmlOptions'=>array('width'=>'80px'),
'template'=>'{view}{update}{delete}{pay}',
'buttons'=>array(
'pay'=>array(
'label'=>'Pay',
'imageUrl'=>Yii::app()->request->baseUrl.'/images/pay.png',
'url'=>'Yii::app()->createUrl("commissions/pay", array("id"=>$data->id))',
'options'=>array('class'=>'pay'),
'visible'=>'$data->status == "unpaid"',
),
),
),
And here’s my controller.
public function actionPayAll($id){
if(Yii::app()->request->isPostRequest){
$commissions = Commissions::model()->findAllByAttributes(array('salesrep_id'=>$id));
$data = '';
foreach($commissions AS $commission){
if($commission->status !== 'paid'){
$commission->status = 'paid';
if(!$commission->save()){
throw new CHttpException(400,'Error Saving Data');
}
}
}
echo 'All commissions Paid';
}else{
throw new CHttpException(400,'Invalid request on PayAll. Please do not repeat this request again.');
}
}
The error i get is:
Error 400: <h1>CHttpException</h1>
<p>Invalid request on PayAll. Please do not repeat this request again. (/var/www/html/yii/salesrepview/protected/controllers/CommissionsController.php:154)</p><pre>#0 [internal function]: CommissionsController->actionPayAll('2')
#1 /var/www/html/yii/framework/web/actions/CAction.php(104): ReflectionMethod->invokeArgs(Object(CommissionsController), Array)
#2 /var/www/html/yii/framework/web/actions/CInlineAction.php(48): CAction->runWithParamsInternal(Object(CommissionsController), Object(ReflectionMethod), Array)
#3 /var/www/html/yii/framework/web/CController.php(300): CInlineAction->runWithParams(Array)
#4 /var/www/html/yii/framework/web/filters/CFilterChain.php(134): CController->runAction(Object(CInlineAction))
#5 /var/www/html/yii/framework/web/filters/CFilter.php(41): CFilterChain->run()
#6 /var/www/html/yii/framework/web/CController.php(1144): CFilter->filter(Object(CFilterChain))
#7 /var/www/html/yii/framework/web/filters/CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))
#8 /var/www/html/yii/framework/web/filters/CFilterChain.php(131): CInlineFilter->filter(Object(CFilterChain))
#9 /var/www/html/yii/framework/web/CController.php(283): CFilterChain->run()
#10 /var/www/html/yii/framework/web/CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)
#11 /var/www/html/yii/framework/web/CWebApplication.php(277): CController->run('payall')
#12 /var/www/html/yii/framework/web/CWebApplication.php(136): CWebApplication->runController('commissions/pay...')
#13 /var/www/html/yii/framework/base/CApplication.php(158): CWebApplication->processRequest()
#14 /var/www/html/yii/salesrepview/index.php(13): CApplication->run()
#15 {main}</pre>
Any Ideas why this might be happening?
Thanks
Oliver