Example #1
0
 /**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionIndex()
 {
     $app = Yii::app();
     // загружаем основные закладки для админа из раздела с ID = 1
     $dataProvider = $app->cache->get(Bookmarks::CACHE_MAIN_BOOKMARKS);
     if ($dataProvider === false) {
         $model = new Bookmarks();
         $model->section_id = 1;
         $model->user_id = 1;
         $dataProvider = $model->search();
         $app->cache->set(Bookmarks::CACHE_MAIN_BOOKMARKS, $dataProvider, $app->params['cache_duration']);
     }
     $settings = $app->cache->get(Settings::CACHE_SETTINGS);
     if ($settings === false) {
         $settings = Settings::model()->loadSettings();
         $app->cache->set(Settings::CACHE_SETTINGS, $settings, $app->params['cache_duration']);
     }
     $this->render('index', array('app' => $app, 'dataProvider' => $dataProvider, 'settings' => $settings));
 }
Example #2
0
 private function renderBookMarks($id)
 {
     $app = Yii::app();
     if ($app->user->isGuest) {
         $user_id = 1;
     } else {
         $user_id = $app->user->id;
     }
     if ($id > 0) {
         $modelSection = $app->cache->get(BookmarksSections::CACHE_SECTION . $id . $app->user->id);
         if ($modelSection === false) {
             $modelSection = BookmarksSections::model()->findByPk($id);
             $app->cache->set(BookmarksSections::CACHE_SECTION . $id . $app->user->id, $modelSection, $app->params['cache_duration']);
         }
         $title = $modelSection->name;
     } else {
         $title = 'Популярные закладки';
     }
     $dataProvider = $app->cache->get(Bookmarks::CACHE_BOOKMARKS_LIST . $id . $app->user->id);
     if ($dataProvider === false) {
         $model = new Bookmarks();
         $model->section_id = $id;
         $model->user_id = $user_id;
         $dataProvider = $model->search();
         $app->cache->set(Bookmarks::CACHE_BOOKMARKS_LIST . $id . $app->user->id, $dataProvider, $app->params['cache_duration']);
     }
     $this->render('index', array('app' => $app, 'title' => $title, 'dataProvider' => $dataProvider));
 }