Blame view

backend/modules/seo/controllers/RobotsController.php 1.1 KB
d1f8bd40   Alexey Boroda   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  <?php
  
  namespace backend\modules\seo\controllers;
  
  use Yii;
  //
  use thread\app\base\controllers\BackendController;
  
  /**
   * Class RobotsController
   *
   * @package backend\modules\seo\controllers
   * @author FilamentV <vortex.filament@gmail.com>
   * @copyright (c), Thread
   */
  class RobotsController extends BackendController
  {
      public $title = 'Robots.txt';
      public $name = 'Robots.txt';
      public $defaultAction = 'update';
      public $layout = 'robots';
  
      /**
       * @return array
       */
      public function actions()
      {
          return [];
      }
  
      /**
       * Перезаписуем robots.txt
       * @return string
       */
      public function actionUpdate()
      {
          $robotsTextPath = Yii::getAlias('@frontend-web') . '/robots.txt';
  
          $post = Yii::$app->getRequest()->post('robots');
          if ($post) {
              file_put_contents($robotsTextPath, $post);
          }
  
          if (!file_exists($robotsTextPath)) {
              fopen($robotsTextPath, 'w+');
          }
          $robotsTxt = file_get_contents($robotsTextPath);
  
  
          return $this->render('_form', ['robotsTxt' => $robotsTxt]);
      }
  }