Exemplo n.º 1
0
 /**
  * Updates an existing Meta model.
  * If update is successful, the browser will be redirected to the 'meta' page.
  * @param $id
  * @return string
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionUpdateMeta($id)
 {
     /* @var $model Meta */
     $model = Meta::find()->where(['key' => $id])->one();
     if ($model !== null) {
         if ($model->load($_POST) && $model->validate()) {
             if ($model->save()) {
                 Yii::$app->session->setFlash('success', Yii::t('app', 'Record has been saved'));
                 $returnUrl = Yii::$app->request->get('returnUrl', ['meta']);
                 switch (Yii::$app->request->post('action', 'save')) {
                     case 'next':
                         return $this->redirect(['create-meta', 'returnUrl' => $returnUrl]);
                     case 'back':
                         return $this->redirect($returnUrl);
                     default:
                         return $this->redirect(Url::toRoute(['update-meta', 'id' => $model->getPrimaryKey(), 'returnUrl' => $returnUrl]));
                 }
             }
         } else {
             return $this->render('updateMeta', ['model' => $model]);
         }
     } else {
         throw new NotFoundHttpException('Meta tag ' . $id . ' not found');
     }
 }
Exemplo n.º 2
0
 public static function registrationMeta()
 {
     if (Yii::$app->request->isAjax === false && !BackendModule::isBackend()) {
         $cacheName = Yii::$app->getModule('seo')->cacheConfig['metaCache']['name'];
         $cacheExpire = Yii::$app->getModule('seo')->cacheConfig['metaCache']['expire'];
         $metas = Yii::$app->getCache()->get($cacheName);
         if ($metas === false) {
             $metas = Meta::find()->all();
             Yii::$app->getCache()->set($cacheName, $metas, $cacheExpire);
         }
         foreach ($metas as $meta) {
             Yii::$app->controller->getView()->registerMetaTag(['name' => $meta->name, 'content' => $meta->content], $meta->key);
         }
     }
 }
 public function beforeAction()
 {
     /* @var $controller Controller */
     $controller = $this->owner;
     if (\Yii::$app->request->url == "/") {
         /* @var $metas Meta[] */
         if (\Yii::$app->getCache()->exists($this->cacheName)) {
             $metas = \Yii::$app->getCache()->get($this->cacheName);
         } else {
             $metas = Meta::find()->all();
             \Yii::$app->getCache()->set($this->cacheName, $metas, $this->cacheExpire);
         }
         foreach ($metas as $meta) {
             $controller->getView()->registerMetaTag(['name' => $meta->name, 'content' => $meta->content], $meta->key);
         }
     }
 }