The folder with view templates is not directly accessible in yii2 so there is no way to refer the csv file there from javascript.
The most simple way to deal with it is to put the csv file in the web
folder.
For example you can put your csv file to web/data
folder. To get the url for the file you can use url helper.
\yii\helpers\Url::to('@web/data/temperatures.csv');
It's better to use the url manager to get the url because it will take care of handling the base url for you, that might be different in different environments. For example final url will probably be /data/temperatures.csv
in production but it can be /web/data/temperatures.csv
in development.
Another option is to make action that will send the file.
In that case you can leave the temperatures.csv
where it is. You need to make a new action in your controller, for example getTemperatures
.
public function actionGetTemperatures()
{
$file = \Yii::getAlias('@app/views/controller/temperatures.csv');
return \Yii::$app->response->sendFile($file);
}
Then you will use the url of this action in javascript.
\yii\helpers\Url::to(['controller/get-temperatures']);
The advantage of this solution is, that it allows you to control whether the user is allowed to access the file.