ArticlesController.php 757 B

12345678910111213141516171819202122232425
  1. <?php
  2. namespace app\controllers;
  3. use yii\web\Controller;
  4. class ArticlesController extends Controller
  5. {
  6. public function actionIndex(){
  7. $url = \Yii::$app->request->pathInfo;
  8. if( $url == 'articles/' || $url == 'article/' || $url == 'article' ){
  9. $queryString = \Yii::$app->request->queryString?'?'.\Yii::$app->request->queryString:'';
  10. $this->redirect('/articles'.$queryString, 301);
  11. return '';
  12. }
  13. $news_query = \app\models\front\News::find()->joinWith('topics t')
  14. ->groupBy('news.id')
  15. ->andFilterWhere(['news.type'=>6]);
  16. return $this->render("index",["news_query"=>$news_query]);
  17. }
  18. public function actionView(int $id):string {
  19. $this->redirect('/news/'.$id, 301);
  20. return '';
  21. }
  22. }