-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArticleController.php
41 lines (34 loc) · 1000 Bytes
/
ArticleController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* Created by PhpStorm.
* User: ivphpan
* Date: 21.07.15
* Time: 11:18
*/
namespace app\modules\cms\controllers;
use app\modules\cms\models\Article;
use yii\web\Controller;
use yii\web\HttpException;
class ArticleController extends Controller{
public function actionList($type)
{
$item = new Article();
$typeId = Article::getTypeIdByAlias($type);
if(!$typeId)
{
throw new HttpException(404,'Категория статей не найдена');
}
$item->type = $typeId;
$items = Article::find()->type($type)->all();
return $this->render('list',['items'=>$items,'item'=>$item]);
}
public function actionView($type,$alias)
{
$item = Article::find()->type($type)->alias($alias)->one();
if(!$item)
{
throw new HttpException(404,'Статья не найдена');
}
return $this->render('view',['item'=>$item,'type'=>$type]);
}
}