Disable Yii Log on Action Controller

Well, i found something interesting yesterday that might be useful for Yii developer when they deal with restful api or JSON output with Yii framework. Sometimes it is good to disable Log output in order to return proper JSON or restful api calls. In that case, you can try to do the following,

        foreach (Yii::app()->log->routes as $route)
        {   
                if ($route instanceof CWebLogRoute || $route instanceof CFileLogRoute || $route instanceof YiiDebugToolbarRoute)
                {   
                        $route->enabled = false;
                }   
        } 

However, if you still seeing your JSON or Restful api output being 'unclean', this is most likely caused by preload options on your config.php file. Preload will always run earlier than whatever you have defined in your action controller. In order to bypass this, the only way is to dive into these extensions and provide certain validation to prevent it from running unnecessary. Sometimes, you will see facebook api appending javascript and meta tag into your json call, in that case, you can add in a new 'enabled' property on your facebook extension and disabled upon your action controller initialization. You can place the following code below to shut up facebook entirely upon running your action controller method.

Yii::app()->facebook->enabled = false;

the enabled property have to be written by you as a new property on facebook extension class file. And the other condition to prevent certain method to run will also have to be written by you since Yii doesn't provide a more graceful method to disable output before preload or extensions that are not managed by them