/**
  * Finds the WidgetText model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return WidgetText the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = WidgetText::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #2
0
 /**
  * @return string
  */
 public function run()
 {
     $cacheKey = [WidgetText::className(), $this->key];
     $content = \Yii::$app->cache->get($cacheKey);
     if (!$content) {
         $model = WidgetText::findOne(['key' => $this->key, 'status' => WidgetText::STATUS_ACTIVE]);
         if ($model) {
             $content = $model->body;
             \Yii::$app->cache->set($cacheKey, $content, 60 * 60 * 24);
         }
     }
     return $content;
 }
Example #3
0
 /**
  * @return string
  */
 public function run()
 {
     $cacheKey = [WidgetText::className(), $this->key];
     $content = Yii::$app->cache->get($cacheKey);
     if (!$content) {
         $model = WidgetText::findOne(['key' => $this->key, 'status' => WidgetText::STATUS_ACTIVE]);
         if (!$model) {
             //try find en-us locale
             $pos = strrpos($this->key, '.');
             $base = substr($this->key, 0, $pos);
             $this->key = $base . '.' . Yii::$app->sourceLanguage;
             $model = WidgetText::findOne(['key' => $this->key, 'status' => WidgetText::STATUS_ACTIVE]);
         }
         if ($model) {
             $content = $model->body;
             Yii::$app->cache->set($cacheKey, $content, 60 * 60 * 24);
         }
     }
     return $content;
 }
Example #4
0
 private function processRobotsRow($key, $title)
 {
     $model = WidgetText::findOne(['key' => $key, 'domain_id' => \Yii::$app->user->identity->domain_id]);
     if (empty($model)) {
         $this->saveRobotsRow($key, $title);
     }
 }