\yii\web\Response accessible only in dev env

Hi,

I am trying to serve pictures that are one level above the @app folder in order to prevent direct access.

To do so I use an ImageController with a view action like this.


    public function actionView($filePath) {




        $pos = strrpos($filePath, '.');

        $ext = substr($filePath, $pos + 1);

        $mime = '';


        $storagePath = Yii::getAlias('@app/../images/' . $filePath); //two levels over web

        $image;

        if (in_array($ext, ['jpeg', 'JPG', 'JPEG', 'jpg', 'jpe'])) {

            $mime = 'image/jpeg';

        } else {

            if (in_array($ext, ['png', 'PNG'])) {

                $mime = 'image/png';

            }

        }


        Yii::$app->response->format = yii\web\Response::FORMAT_RAW;

        Yii::$app->response->headers->add('content-type', $mime);


        Yii::$app->response->data = file_get_contents($storagePath);


        return Yii::$app->response; }

Everything works perfectly as long as I use YII_ENV = ‘dev’. But as soon as I comment out the define YII_ENV in the index file in order to default to Yii_ENv = ‘prod’ It fails and the error reported is

[b]

class ‘Yii\web\Response’ not found. [/b]

Is this normal behavior and why ?

Doesn’t sound normal. About why — no idea. Try debugging.

I cannot get more info from the debug tool bar

Eventually made it out.


  Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;

instead of




  Yii::$app->response->format = yii\web\Response::FORMAT_RAW;