How to get response as json format(application/json) in yii?

برنامه نویسی php
How to get response as json format(application/json) in yii?

Create this function in your (base) Controller:

protected function renderJSON($data)
{
    header('Content-type: application/json');
    echo CJSON::encode($data);
    foreach (Yii::app()->log->routes as $route) {
        if($route instanceof CWebLogRoute) {
            $route->enabled = false; // disable any weblogroutes
        }
    }
    Yii::app()->end();
}

Leave a Reply

Your email address will not be published. Required fields are marked *