Exemple #1
0
 public function actionCatch($url = null)
 {
     $link = Links::findOne(['url' => '/' . $url]);
     if (!$link) {
         echo '404 Not found!';
         return false;
     }
     $this->layout = $link->layout->name;
     if ($link->description) {
         Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => $link->description]);
     }
     if ($link->keywords) {
         Yii::$app->view->registerMetaTag(['name' => 'keywords', 'content' => $link->keywords]);
     }
     if (isset($link->id)) {
         $contents = Contents::find()->where(['links_id' => $link->id])->orderBy(['seq' => SORT_ASC])->all();
         for ($i = 0; $i < count($contents); $i++) {
             $contents[$i]->text = preg_replace_callback('/(\\{{)(\\S+)(}})/', "self::getModule", $contents[$i]->text);
             $contents[$i]->text = preg_replace_callback('/(\\[\\[)(\\S+)(]])/', "self::getWidget", $contents[$i]->text);
         }
     }
     return $this->render($link->view->name, ['link' => $link, 'contents' => $contents]);
 }
 public function actionSaveContent($links_id, $categories_id = null)
 {
     if (Yii::$app->request->isAjax) {
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         $contents = Contents::find()->where(['links_id' => $links_id])->orderBy(['seq' => SORT_ASC])->all();
         if (Yii::$app->request->post()) {
             foreach ($contents as $index => $content) {
                 if (Yii::$app->request->post('content-' . $index)) {
                     $contents[$index]->load(Yii::$app->request->post());
                     $contents[$index]->text = Yii::$app->request->post('content-' . $index);
                     $contents[$index]->save();
                 }
             }
         }
         return ['flash' => 'success', 'message' => 'Изменения приняты'];
     }
 }