Question on Redirect

Hi,

I need to validate before an record can be deleted, my validation code put inside the actioneDelete(), if after I perform checking and denied the delete, how can I redirect user to previous page?

I search only found




$this->redirect(Yii::app()->user->returnUrl);



Can I return user to the page (referrer) before he click the deletion ?

Thanks.

Are you using linkButton?

Yes, exactly, it is generated by crud.




echo CHtml::linkButton('Delete accounts',array('submit'=>array('delete','id'=>$model->acc_id),'confirm'=>'Are you sure?'));



:huh:

I can’t figure out what you want.

linkButton refreshs current page.




protected function processAdminCommand()

{

   (...)

   $this->refresh();

}



I think you can store the previous page information in session.

I am refering to this section of code (generated by yii crud) :




public function actionDelete()

{

	if(Yii::app()->request->isPostRequest)

	{

		// we only allow deletion via POST request

		$this->loadaccounts()->delete();

		$this->redirect(array('list'));

	}

	else

		throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');

}



The linkButton is actually located under "index.php?r=controller_name/show&id=1"

I added a if condition to validate before delete




public function actionDelete()

{

	if(Yii::app()->request->isPostRequest)

	{

		// we only allow deletion via POST request

		if(myValidate()) {

			$this->loadaccounts()->delete();

			$this->redirect(array('list'));

		} else {

			# Delete is denied, and now should redirect to previous page

			# but I not sure how to, if keep the previous page inside session

			# require additional work/maintenance, just try to use any

			# function/method the come with Yii.

		}

	}

	else

		throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');

}



Any ideas?

Did you try:




$this->redirect(Yii::app()->request->urlReferrer);



You should check that urlReferrer is what you really want.

Yes, it works! This is what I looking at… Thanks you all guys !! :lol: