StatsController.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace manager\controllers;
  3. use manager\models\News;
  4. use Yii;
  5. class StatsController extends BaseController
  6. {
  7. public function actionIndex()
  8. {
  9. $model = new News();
  10. return $this->render('index', ['model' => $model]);
  11. }
  12. // месяц
  13. public function actionAuthors()
  14. {
  15. $model = new News();
  16. return $this->render('authors', ['model' => $model]);
  17. }
  18. // по дням
  19. public function actionAuthorsd()
  20. {
  21. $model = new News();
  22. return $this->render('authorsd', ['model' => $model]);
  23. }
  24. // по дням csv
  25. public function actionCsv()
  26. {
  27. if (Yii::$app->request->isGet){
  28. $author = Yii::$app->request->get('author');
  29. $m = Yii::$app->request->get('m');
  30. $str = $this->renderpartial('csv', ['author'=>$author, 'm'=>$m]);
  31. Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
  32. Yii::$app->response->headers->set('Content-type', ['text/csv']);
  33. Yii::$app->response->headers->set('Content-Transfer-Encoding', ['binary']);
  34. header("Pragma: no-cache");
  35. header("Expires: 0");
  36. header('Content-Disposition: attachment; filename="'.basename($author.'.csv').'"');
  37. header('Content-Length: ' . strlen($str));
  38. return $str;
  39. }
  40. return "Нет данных.";
  41. }
  42. }