1 | <?php |
||
28 | class DefaultController extends Controller |
||
29 | { |
||
30 | /** |
||
31 | * @inheritdoc |
||
32 | */ |
||
33 | public function behaviors() |
||
34 | { |
||
35 | return [ |
||
36 | 'pageCache' => [ |
||
37 | 'class' => 'yii\filters\PageCache', |
||
38 | 'only' => ['index', 'robots-txt'], |
||
39 | 'duration' => Yii::$app->sitemap->cacheExpire, |
||
40 | 'variations' => [Yii::$app->request->get('id')], |
||
41 | ], |
||
42 | ]; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Action for sitemap/default/index |
||
47 | * |
||
48 | * @access public |
||
49 | * @return string |
||
50 | */ |
||
51 | public function actionIndex($id = 0) |
||
52 | { |
||
53 | $sitemap = Yii::$app->sitemap->render(); |
||
54 | if (empty($sitemap[$id])) { |
||
55 | throw new NotFoundHttpException(Yii::t('yii', 'Page not found.')); |
||
56 | } |
||
57 | |||
58 | Yii::$app->response->format = Response::FORMAT_RAW; |
||
59 | $headers = Yii::$app->response->headers; |
||
60 | $headers->add('Content-Type', 'application/xml'); |
||
61 | $result = $sitemap[$id]['xml']; |
||
62 | if (Yii::$app->sitemap->enableGzip) { |
||
63 | $result = gzencode($result); |
||
64 | $headers->add('Content-Encoding', 'gzip'); |
||
65 | $headers->add('Content-Length', strlen($result)); |
||
66 | } |
||
67 | return $result; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Action for sitemap/default/robot-txt |
||
72 | * |
||
73 | * @access public |
||
74 | * @return string |
||
75 | */ |
||
76 | public function actionRobotsTxt() |
||
86 | } |
||
87 |