Пример #1
0
 /**
  * Finds the MetaBase model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return MetaBase the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Meta::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #2
0
 /**
  * @param string $route
  * @return array
  */
 public function getMeta($route)
 {
     //        $cache = Yii::$app->{$this->cache};
     //        $cacheId = $this->componentId . '|routes|' . $route . '|city|' . $this->city;
     //        $aMeta = $cache->get($cacheId);
     //        if ($aMeta) {
     //            return $aMeta;
     //        }
     $aMeta = [];
     $model = Meta::findOne(['hash' => md5($route)]);
     if (!empty($model)) {
         $info = $model->toArray();
         foreach ($info as $idData => $data) {
             if (!empty($data)) {
                 $aMeta[$idData] = $data;
             }
         }
         //находим альтернативный текст для города
         $aMeta = $this->replaceInfotext($aMeta);
         //TODO отключаем формирование ссылок в тексте по ключам
         $aMeta = $this->setLinks($aMeta, ['infotext_before', 'infotext_after']);
     } elseif (Yii::$app->request->get('seo') === 'add') {
         //при передаче гетом переменной seo = add страница добавиться в базу, только если ее там нет
         $oMeta = new Meta();
         $oMeta->setRoute($route);
         $oMeta->save();
     }
     //        $oTagDependency = new \yii\caching\TagDependency(['tags' => self::CACHE_TAG]);
     //
     //        $cache->set($cacheId, $aMeta, $this->cacheDuration, $oTagDependency);
     return $aMeta;
 }