Message Alert From Controller

Hi, I got service that connected with other services across the web.

When I ask another server, and receive error from it, i need to stop executing of my code and show error, that I receive, in view, by alert javascript.

How do this better?

Can I render javascript alert message from controller?

if (isset(Yii::app()->params['error'][$error])) {

	$result['message'] = Yii::app()->params['error'][$error][Yii::app()->session['FROM'].'_message'];


I need something like this:

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

You simply cant 'couse a javascript alert is a VIEW stuff. You are using MVC pattern with Yii.

If you are using ajax to communicate with the controller action, you can watch for the errors and then display them as alerts.

Some javascript like this in your view:

$.ajax({ type : 'post'

    , url: 'controller/action'

    , data: ({ data: someData })

    , dataType: 'json'

    , success: function(data){

        if(data.error == 0){

            // No error occured

        } else {

            alert("Error: " + data.error);




Then in your controller action:

$data = Yii::app()->request->getParam('data');

if(some error is detected){

    echo json_encode(array('error' => 'There was an error.'));