Yii Delete Function

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(&#036;id)


{


	if(Yii::app()-&gt;request-&gt;isPostRequest)


	{


		// we only allow deletion via POST request


		&#036;this-&gt;loadModel(&#036;id)-&gt;delete();





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


		if(&#33;isset(&#036;_GET['ajax']))


			&#036;this-&gt;redirect(isset(&#036;_POST['returnUrl']) ? &#036;_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!

if the error code is 404 than take a look your url(URL manager). and also take a look this method inside your controller.:


public function loadModel($id)

	{

		$model=EnglishGames::model()->findByPk((int)$id);

		if($model===null)

			throw new CHttpException(404,'The requested page does not exist.');

		return $model;

	}

If it can not find a model it gives exception. so if you ask /contollerName/delete/10 than make sure there is a row which primary key is 10, otherwise it can not find the model and it gives the 404 error as u see.