Blame view

frontend/components/Seo.php 721 Bytes
c7f222e2   Artem   first
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
  <?php
  namespace frontend\components;
  use common\models\SeoDataSearch;
  use common\models\SeoData;
  use yii\base\Widget;
  use yii\helpers\Url;
  
  class Seo extends Widget
  {
      private $url;
      private $source;
      public  $row;
  
      public function init(){
          $this->url   = Url::canonical();
          $this->source = 'seo';
          parent::init();
  
      }
  
  
      public function run()
      {
          $widgetData = $this->findModel();
  
          return $widgetData->{$this->row};
      }
  
      protected function findModel()
      {
          if (($model = SeoData::findOne(['url'=>$this->url, 'model'=>$this->source])) !== null) {
              return $model;
          } else {
              return new SeoDataSearch();
          }
      }
  }