There are two approaches to having Yii render the JSON or XML data. The first and the easiest approach is to create a JSON or XML view file and, from every action, call
$this->render('json'). While this is simple, it forces us to store a lot of information and explicitly call the
render() method in each action. If we're extending a class that modifies the
render() method, this can be extremely problematic if we want to make changes later. Another issue with this approach is that it treats errors as separate response types. When throwing an error with this approach, Yii will want to render the error as HTML rather than JSON. Depending upon our logging and debug level, this can cause our API to return the wrong data ...