Creating Delete Button In Cbuttoncolumn

Hello,

I am trying to create a Delete button in my CGridView in the CButtonColumn.

This is what my CGridView Widget Looks like:




<?php $this->widget('zii.widgets.grid.CGridView', array(

                        'dataProvider'=>$projectDataProvider,

                        'columns'=> array(

                            'name',

                            'short_description:html',

                            'location', 

                            array(

                                'header' => 'Date Created',

                                'name'=>'create_time',

                                'value'=>'date("M j, Y", $data->create_time)',

                            ),

                            array(

                                'header'=>'<i class="icon-user"></i> Created By',

                                'name'=>'create_id',

                                'value'=>'$data->create->username',                            

                            ),

                            array(

                                'class'=>'CButtonColumn',

                                'template'=>'{edit}',

                                'buttons'=>array(

                                    'edit'=> array(

                                        'label'=>'<i class="icon-edit"></i> View',

                                        'url'=>'Yii::app()->createUrl("project/view", array("id"=>$data->id))',

                                        'options'=>array(

                                            'class'=>'btn purple'

                                        )

                                    ),

                                )

                            ),

                            array(

                                'class'=>'CButtonColumn',

                                'template'=>'{remove}',

                                'buttons'=>array(

                                    'remove'=> array(

                                        'label'=>'<i class="icon-remove"></i> Delete',

                                        'url'=>'Yii::app()->createUrl("project/delete", array("id"=>$data->id))',

                                        'options'=>array(

                                            'class'=>'btn red delete',

                                            'onclick' => 'return confirm("Are you sure want to delete this project?");',

                                        )

                                    )

                                )

                            ),

                        ),

                        'itemsCssClass' => 'table table-striped table-bordered table-advance table-hover'

                    )); ?>



This is my controller:




	public function actionDelete($id)

	{

		$this->loadModel('Project', $id)->delete();


		// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser

		if(!isset($_GET['ajax']))

			$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('site/admin'));

	}



When trying to delete, I keep getting the error in my application log:

[exception.CHttpException.400] exception ‘CHttpException’ with message ‘Your request is invalid.’ in C:\xampp\htdocs\yii\framework\web\CController.php:1118

Any help would be excellent.

Thanks.

You can mix your button column:




                            array(

                                'class'=>'CButtonColumn',

                                'template'=>'{edit}'remove}',

                                'buttons'=>array(

                                    'edit'=> array(

                                        'label'=>'<i class="icon-edit"></i> View',

                                        'url'=>'Yii::app()->createUrl("project/view", array("id"=>$data->id))',

                                        'options'=>array(

                                            'class'=>'btn purple'

                                        )

                                    ),

                                'buttons'=>array(

                                    'remove'=> array(

                                        'label'=>'<i class="icon-remove"></i> Delete',

                                        'url'=>'Yii::app()->createUrl("project/delete", array("id"=>$data->id))',

                                        'options'=>array(

                                            'class'=>'btn red delete',

                                            'onclick' => 'return confirm("Are you sure want to delete this project?");',

                                        )

                                    )

                                )

                                )

                            ),



Then check that your destination url is correct.