php namespace app modules shop controllers use Yii use yii web Control

 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace app\modules\shop\controllers;
use Yii;
use yii\web\Controller;
use app\controllers\ZdController;
use app\models\ClassPagination;
use app\modules\shop\models\Categories;
use app\modules\shop\models\AddGoods;
use app\modules\shop\models\Goods;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
class MainController extends ZdController
{
public function actionIndex()
{
$this->zd_title = \Yii::t('app', 'TITLE_SHOP');
$query = Categories::find()->where(['user' => '0', 'parent' => '0']);
$pagin = new ClassPagination();
$pagination = $pagin->pagin($query, $this->module->params['page_size_cats']);
$cats = $pagin->output($query);
return $this->render('index', [
'cats' => $cats,
'pagination' => $pagination,
]);
}
public function actionMy()
{
if(\Yii::$app->user->isGuest)
{
Yii::$app->getSession()->setFlash('warning', Yii::t('app', 'ERROR_AUTH'));
return $this->redirect(Url::to(['/shop']));
}
$model = new AddGoods();
if($model->load(\Yii::$app->request->post()))
{
if($model->addGood())
{
Yii::$app->getSession()->setFlash('success', Yii::t('app', 'SHOP_GOOD_ADDED'));
return $this->redirect('/shop/main/my');
}
else
{
Yii::$app->getSession()->setFlash('warning', Yii::t('app', 'SHOP_GOOD_NOT_ADDED'));
return $this->redirect('/shop/main/my');
}
}
return $this->render('my', [
'model' => $model,
]);
}
public function actionMygoods()
{
$this->zd_title = \Yii::t('app', 'SHOP_MY_GOODS');
$query = Goods::find()->where(['user' => \Yii::$app->user->getId()])->orderBy('moderate');
$model = new ClassPagination();
$pagination = $model->pagin($query, $this->module->params['page_my_goods']);
$goods = $model->output($query);
return $this->render('mygoods', [
'goods' => $goods,
'pagination' => $pagination,
]);
}
}