Converting Yii2 responses to Json responses for mobile apps
<p>I have a Yii2 App and we want to start building restful services for the mobile devices. </p>

<p>I have the URL's as</p>

<pre><code>"users/photos"
"users/videos"
"users/profile"
</code></pre>

<p>They all render Html response. What I would like to do is to pass another parameter in the URL and convert the response into JSON and send all the view variables as JSON output. So, I don't have worry about code duplication.</p>

<p>What is the best way to achieve this?</p>