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 ?
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.');
}