Hey everyone. I am unable to delete entries from table without hitting refresh on the View file. I was wondering how to ensure that the ‘id’ passed by the view to controller changes controller value–I’m just guessing this is the problem?
If I am deleting several entries from a table, if I don’t refresh the page then it attempts to delete the entry that was previously viewed/deleted.
ie. I view entry with ‘id’ 33. I delete entry 33 successfully. Then I go to the view for entry ‘id’=17. When I call delete the follow error appears:
POST http…index.php/medications/delete/33 404 (CHttpException)
I see clearly that the problem is that the wrong id is being appended to the delete call (here should be 17 instead of 33). But I can’t figure out where the problem is arising from. I checked the view page and it has the right seems to be pulling the correct value for $model->id. I don’t understand why the ‘id’ in model isn’t the same as ‘id’ in the view call.
View file Delete call:
<?php echo CHtml::link(‘Delete’,"#", array(‘data-role’=>‘button’, ‘data-icon’=>‘delete’, “submit”=>array(‘delete’, ‘id’=>$model->id), ‘confirm’ => ‘Are you sure to confirm?’)); ?>
Controller actionDelete:
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.');
}
How can I ensure that the ‘id’ in the model is being update suitably?
Thanks!