Hi All,
I’m having some problems deleting with pagination switched on.
I’ve added a delete link to a customised index page which works fine under normal circumstances but after adding pagination in the data provider, if I attempt to delete an item from page 2 it actually removes the equivalent item from the first page (deleting first item in page 2 deletes first item in page 1; deleting second item in page 2 deletes second item in page 1, etc).
Here are my controller’s index and delete actions:
public function actionIndex()
{
$vehicles = Vehicle::model()->vehiclesOfLoggedInUser();
$dataProvider = new CArrayDataProvider($vehicles, array(
'sort'=>array(
'attributes'=>array(
'registration', 'make', 'model'),
),
'keyField' => 'vehicle_id',
'pagination'=>array(
'pageSize'=>10,
),
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
public function actionDelete($id)
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadModel($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('index'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
And the delete link in my view:
<?php echo CHtml::Link('Delete Vehicle', '#', array('submit'=>array('vehicle/delete','id'=>$data->vehicle_id),'confirm'=>'Are you sure?'));
I’m assuming it’s because the contents of the second page isn’t available to POST but is there away to fix this?
Any suggestions gratefully received!