在actionDelete我们如何在yii中使用flash重定向同一页面

时间:2016-06-11 08:37:53

标签: php redirect yii

if(!empty($check)) {
    Yii::app()->user->setFlash('failure',"example");
    $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
    //its not redirecting
}

1 个答案:

答案 0 :(得分:0)

试试这个,

 public function actionDelete($id) {

    try {
        $this->loadModel($id)->delete();
        return $this->redirect(['create']);
    } catch (CDbException $e) {
            if (1451 == $e->errorInfo[1])
                    {
                            // Your message goes here
                            $msg = 'Unable to delete this field.';
                    }
                    else
                    {
                            $msg = 'Deletion failed';  
                    }

                    if (isset($_GET['ajax']))
                    {
                            throw new CHttpException(400, $msg);
                    }               
                    else
                    {
                            Yii::app()->user->setFlash('error', $msg);
                    }
    }
}