/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return BookmarksSections the loaded model * @throws CHttpException */ public function loadModel($id) { $model = BookmarksSections::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
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)); }