【问题标题】:yiiframework Action delete is not showing setflashyiiframework Action delete 不显示 setflash
【发布时间】:2011-08-23 06:10:06
【问题描述】:
    public function actionDelete($id)
{
    if(Yii::app()->request->isPostRequest)
    {
        // we only allow deletion via POST request
        try 
        {
            $this->loadModel($id)->delete();
            // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
                if(!isset($_GET['ajax']))
                    $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));          
        }
        catch (Exception $e) 
        {
            throw new CTestException('User in use, Delete Refrences.');
            //Yii::app ()->user->setFlash ( 'error', "User in use, Delete Refrences." );
        }


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

我想捕获内部异常并显示警报。它的 setflash 无法正常工作,而且如果我抛出自定义异常,它也会警告堆栈错误 500,这是我试图处理的异常。

【问题讨论】:

  • 你的setflash 行被注释掉了,所以它不会被执行。

标签: php ajax yii


【解决方案1】:

您需要将 setFlash 调用放在 throw 之前,因为 throws 以与 return 语句类似的方式结束函数。

另外,取消注释该语句。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-14
    • 1970-01-01
    • 2023-01-24
    • 1970-01-01
    相关资源
    最近更新 更多