Delete result of CGridView

I’m using CGridView, and there’s a CButtonColumn.

The delete button will send a XHR to controller, like this




MyController extends Controller

{

    public function actionDelete()

    {

        $id = isset($_GET['id']) ? $_GET['id'] : 0;

        $model = SomeModel::model()->findByPk($id);


        if(false == empty($model))

            $model->delete();

        else {

            // do something that popup an alert to tell failure

        }

    }

}



I have trid renderText and echo <script>alert(‘xxx’)</script> directly, but both failed.

CHttpException can popup an alert, but not a purify message.

That’s it, could anyone help me?

RT ;)

Could someone help me?

I dont’t find the code “echo <script>alert(‘xxx’)</script>”?

I dont’t understand what are you mean?

You can echo “<script>alert(‘xxx’)</script>”; in the controller

Thanks guy, but I have tried that, and failed.

CGridview only request that action for post data, and no matter what u render, there’s no work.

Seems that need throw a CHttpException or send a header like 404 or 500, but I don’t know how to define a purify message…

Try these codes:


$error=Yii::app()->errorHandler->error;

if($error['code']=='404')

    echo "<script>alert('xxx');</script>";

elseif($error['code']=='500')

    echo "<script>alert('xxx');</script>";

else

    echo "<script>alert('xxx');</script>";

error property read-only (available since v1.0.6)

public array getError()

code - the HTTP status code (e.g. 403, 500)

type - the error type (e.g. ‘CHttpException’, ‘PHP Error’)

message - the error message

file - the name of the PHP script file where the error occurs

line - the line number of the code where the error occurs

trace - the call stack of the error

source - the context source code where the error occurs

你可以用$error=Yii::app()->errorHandler->error;

$error[‘code’]去判断错误代码!

还是说两句中文吧,说英文都快把我憋疯了!