yiiframework动作删除不显示setflash

时间:2011-08-23 06:10:07

标签: php ajax yii

    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的堆栈,这是我试图处理的异常。

1 个答案:

答案 0 :(得分:0)

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

此外,取消注释声明。