PageController.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Author: lf
  4. * Blog: https://blog.feehi.com
  5. * Email: job@feehi.com
  6. * Created at: 2016-04-02 22:48
  7. */
  8. namespace frontend\controllers;
  9. use Yii;
  10. use common\services\ArticleServiceInterface;
  11. use yii\web\NotFoundHttpException;
  12. class PageController extends \yii\web\Controller
  13. {
  14. /**
  15. * single page
  16. *
  17. * @param string $name
  18. * @return string
  19. * @throws yii\web\NotFoundHttpException
  20. * @throws yii\base\InvalidConfigException
  21. */
  22. public function actionView($name = '')
  23. {
  24. if ($name == '') {
  25. $name = Yii::$app->getRequest()->getPathInfo();
  26. }
  27. /** @var ArticleServiceInterface $service */
  28. $service = Yii::$app->get(ArticleServiceInterface::ServiceName);
  29. $model = $service->getArticleSubTitle($name);
  30. if (empty($model)) {
  31. throw new NotFoundHttpException('None page named ' . $name);
  32. }
  33. $template = "view";
  34. isset($model->category) && $model->category->template != "" && $template = $model->category->template;
  35. $model->template != "" && $template = $model->template;
  36. return $this->render($template, [
  37. 'model' => $model,
  38. 'singlePages' => $service->getSinglePages(),
  39. ]);
  40. }
  41. }