Is there any way to override the view action in the ActiveController by just creating a function in the controller (not creating a new class)?
I have a controller called MediaController. When the user sends a GET request to .../api/media/xyz.jpg I want to send the file xyz.jpg to the user
Actually I need something like this:
public function actionView($filename) {
$mediaPath = \Yii::getAlias('@mediaPath');
return Yii::$app->response->sendFile("$storagePath/$filename", $filename);
}
but it’s not working.
By the way when I run ../api/1.jpg (.jpg at the end of url) I get InvalidRouteException. Why?