在行动上删除我们如何在yii中使用flash在同一页面上重定向


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

试试这个,

 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);
                    }
    }
}

最新更新