'@npm' => '@vendor/npm-asset',
'@dist' => '@app/dist',
'@uploads' => "@yii_app/uploads",
- '@feeds' => '@app/media/feeds',
+ '@feeds' => '@app/feeds',
],
'params' => require dirname(__DIR__, 2) . '/config/params.php',
'timeZone' => 'Europe/Moscow',
*/
public function actionFeed($id)
{
- $dir = Yii::getAlias('@feeds');
- $matches = glob($dir . DIRECTORY_SEPARATOR . "feed_{$id}.xml") ?: [];
- if (!$matches) {
- throw new \yii\web\NotFoundHttpException('Фид ещё не сгенерирован'); }
+ $id = (int)$id;
+
+ $dir = Yii::getAlias('@feeds');
+ $path = $dir . DIRECTORY_SEPARATOR . "feed_{$id}.xml";
+
+ if (!is_file($path)) {
+ Yii::error([
+ 'msg' => 'feed not found',
+ 'alias' => '@feeds',
+ 'dir' => $dir,
+ 'dirReal' => @realpath($dir),
+ 'path' => $path,
+ 'exists' => file_exists($path),
+ ], __METHOD__);
+
+ throw new \yii\web\NotFoundHttpException('Фид ещё не сгенерирован' . $dir);
+ }
- return Yii::$app->response->sendFile($matches[0], basename($matches[0]), [
+ return Yii::$app->response->sendFile($path, "feed_{$id}.xml", [
'mimeType' => 'application/xml; charset=utf-8',
- 'inline' => true,
+ 'inline' => true,
]);
}