Yii how to redirect to absolute URL with json response

user3449452 picture user3449452 · Apr 17, 2014 · Viewed 9.2k times · Source

My Controler

function actionLogin()
{
     //After success validation
     $url = $_POST['returnUrl']; // www.example.com/get_response/
     $arr = array('response' => 'Failed', 'msg' => 'login success','tokenKey'=> 'token');

    //How to send the response to url

}

In my above code i have to send the $arr array to $url absolute URL.

I found some solutions for this is it works here?

Yii::$app->getResponse()->redirect('http://newdomain.com');

But i don't know how to use in my case or is there any better way

Answer

hoangvu68 picture hoangvu68 · Apr 17, 2014

In controller, use:

$this->redirect("absolute URL");

If you want redirect to a specific action:

$this->redirect(array('controller/action'));