Пример #1
0
 public function loadModel($id)
 {
     if (!($model = Post::findOne($id))) {
         throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested post does not exist.'));
     }
     return $model;
 }
Пример #2
0
 protected function launch()
 {
     if ($this->post && !$this->post instanceof Post) {
         $this->post = Post::findOne(intval($this->post));
     }
     if (empty($this->post)) {
         throw new InvalidConfigException(Yii::t('gromver.platform', 'Post not found.'));
     }
     if ($this->useHighlights) {
         CkeditorHighlightAsset::register($this->getView());
     }
     echo $this->render($this->layout, ['model' => $this->post]);
 }
Пример #3
0
 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Post the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Post::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested page does not exist.'));
     }
 }
Пример #4
0
 public function createPost($requestInfo)
 {
     //пытаемся найти пункт меню ссылющийся на данный пост
     if ($path = $requestInfo->menuMap->getMenuPathByRoute(MenuItem::toRoute('grom/news/post/view', ['id' => $requestInfo->requestParams['id']]))) {
         unset($requestInfo->requestParams['id'], $requestInfo->requestParams['category_id'], $requestInfo->requestParams['alias']);
         return MenuItem::toRoute($path, $requestInfo->requestParams);
     }
     //ищем пункт меню ссылающийся на категорию данного поста либо ее предков
     if (isset($requestInfo->requestParams['category_id']) && isset($requestInfo->requestParams['alias'])) {
         //можем привязаться к пункту меню ссылающемуся на категорию новостей к которой принадлежит данный пост(напрямую либо косвенно)
         if ($path = $this->findCategoryMenuPath($requestInfo->requestParams['category_id'], $requestInfo->menuMap)) {
             $path .= '/' . $requestInfo->requestParams['alias'] . '.' . $this->postSuffix;
             unset($requestInfo->requestParams['id'], $requestInfo->requestParams['category_id'], $requestInfo->requestParams['alias']);
             return MenuItem::toRoute($path, $requestInfo->requestParams);
         }
     }
     //привязываем ко всем новостям, если пукнт меню существует
     if ($path = $requestInfo->menuMap->getMenuPathByRoute('grom/news/post/index')) {
         $path .= '/' . Post::findOne($requestInfo->requestParams['id'])->category->path . '/' . $requestInfo->requestParams['alias'] . '.' . $this->postSuffix;
         unset($requestInfo->requestParams['id'], $requestInfo->requestParams['category_id'], $requestInfo->requestParams['alias']);
         return MenuItem::toRoute($path, $requestInfo->requestParams);
     }
 }