Commit ab4d7cb1690d4d3bf2d808bb077444722f63c967
1 parent
b427543e
Page + Языковая версия
Showing
35 changed files
with
905 additions
and
197 deletions
Show diff stats
1 | +<?php | |
2 | + | |
3 | +namespace backend\controllers; | |
4 | + | |
5 | +use Yii; | |
6 | +use common\models\Page; | |
7 | +use backend\models\SearchPage; | |
8 | +use yii\web\Controller; | |
9 | +use yii\web\NotFoundHttpException; | |
10 | +use yii\filters\VerbFilter; | |
11 | + | |
12 | +/** | |
13 | + * PageController implements the CRUD actions for Page model. | |
14 | + */ | |
15 | +class PageController extends Controller | |
16 | +{ | |
17 | + public function behaviors() | |
18 | + { | |
19 | + return [ | |
20 | + 'verbs' => [ | |
21 | + 'class' => VerbFilter::className(), | |
22 | + 'actions' => [ | |
23 | + 'delete' => ['post'], | |
24 | + ], | |
25 | + ], | |
26 | + ]; | |
27 | + } | |
28 | + | |
29 | + /** | |
30 | + * Lists all Page models. | |
31 | + * @return mixed | |
32 | + */ | |
33 | + public function actionIndex() | |
34 | + { | |
35 | + $searchModel = new SearchPage(); | |
36 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |
37 | + | |
38 | + return $this->render('index', [ | |
39 | + 'searchModel' => $searchModel, | |
40 | + 'dataProvider' => $dataProvider, | |
41 | + ]); | |
42 | + } | |
43 | + | |
44 | + /** | |
45 | + * Displays a single Page model. | |
46 | + * @param integer $id | |
47 | + * @return mixed | |
48 | + */ | |
49 | + public function actionView($id) | |
50 | + { | |
51 | + return $this->render('view', [ | |
52 | + 'model' => $this->findModel($id), | |
53 | + ]); | |
54 | + } | |
55 | + | |
56 | + /** | |
57 | + * Creates a new Page model. | |
58 | + * If creation is successful, the browser will be redirected to the 'view' page. | |
59 | + * @return mixed | |
60 | + */ | |
61 | + public function actionCreate() | |
62 | + { | |
63 | + $model = new Page(); | |
64 | + | |
65 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
66 | + return $this->redirect(['view', 'id' => $model->page_id]); | |
67 | + } else { | |
68 | + return $this->render('create', [ | |
69 | + 'model' => $model, | |
70 | + ]); | |
71 | + } | |
72 | + } | |
73 | + | |
74 | + /** | |
75 | + * Updates an existing Page model. | |
76 | + * If update is successful, the browser will be redirected to the 'view' page. | |
77 | + * @param integer $id | |
78 | + * @return mixed | |
79 | + */ | |
80 | + public function actionUpdate($id) | |
81 | + { | |
82 | + $model = $this->findModel($id); | |
83 | + | |
84 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
85 | + return $this->redirect(['view', 'id' => $model->page_id]); | |
86 | + } else { | |
87 | + return $this->render('update', [ | |
88 | + 'model' => $model, | |
89 | + ]); | |
90 | + } | |
91 | + } | |
92 | + | |
93 | + /** | |
94 | + * Deletes an existing Page model. | |
95 | + * If deletion is successful, the browser will be redirected to the 'index' page. | |
96 | + * @param integer $id | |
97 | + * @return mixed | |
98 | + */ | |
99 | + public function actionDelete($id) | |
100 | + { | |
101 | + $this->findModel($id)->delete(); | |
102 | + | |
103 | + return $this->redirect(['index']); | |
104 | + } | |
105 | + | |
106 | + /** | |
107 | + * Finds the Page model based on its primary key value. | |
108 | + * If the model is not found, a 404 HTTP exception will be thrown. | |
109 | + * @param integer $id | |
110 | + * @return Page the loaded model | |
111 | + * @throws NotFoundHttpException if the model cannot be found | |
112 | + */ | |
113 | + protected function findModel($id) | |
114 | + { | |
115 | + if (($model = Page::findOne($id)) !== null) { | |
116 | + return $model; | |
117 | + } else { | |
118 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
119 | + } | |
120 | + } | |
121 | +} | ... | ... |
backend/controllers/PageController.php
... | ... | @@ -8,8 +8,6 @@ use backend\models\SearchPage; |
8 | 8 | use yii\web\Controller; |
9 | 9 | use yii\web\NotFoundHttpException; |
10 | 10 | use yii\filters\VerbFilter; |
11 | -use common\models\PageLang; | |
12 | -use yii\data\SqlDataProvider; | |
13 | 11 | |
14 | 12 | /** |
15 | 13 | * PageController implements the CRUD actions for Page model. |
... | ... | @@ -27,33 +25,20 @@ class PageController extends Controller |
27 | 25 | ], |
28 | 26 | ]; |
29 | 27 | } |
28 | + | |
30 | 29 | |
31 | 30 | /** |
32 | 31 | * Lists all Page models. |
33 | 32 | * @return mixed |
34 | 33 | */ |
35 | 34 | public function actionIndex() |
36 | - { | |
37 | - $searchModel = new SearchPage(); | |
38 | - | |
39 | - $_GET['lang_id'] = 1; | |
40 | - | |
35 | + { | |
36 | + $searchModel = new SearchPage(); | |
37 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |
38 | + | |
41 | 39 | return $this->render('index', [ |
42 | - 'dataProvider' => new SqlDataProvider([ | |
43 | - 'sql' => SearchPage::getList(Yii::$app->request->get()), | |
44 | - 'pagination' => [ | |
45 | - 'pagesize' => 30, | |
46 | - ], | |
47 | - 'sort' => [ | |
48 | - 'attributes' => [ | |
49 | - 'page_id', | |
50 | - 'date_add', | |
51 | - 'title', | |
52 | - 'show', | |
53 | - ] | |
54 | - ] | |
55 | - ]), | |
56 | 40 | 'searchModel' => $searchModel, |
41 | + 'dataProvider' => $dataProvider, | |
57 | 42 | ]); |
58 | 43 | } |
59 | 44 | |
... | ... | @@ -77,24 +62,12 @@ class PageController extends Controller |
77 | 62 | public function actionCreate() |
78 | 63 | { |
79 | 64 | $model = new Page(); |
80 | - $page_lang = new PageLang(); | |
81 | - | |
82 | - if ($model->validate() | |
83 | - && $page_lang->load(Yii::$app->request->post()) | |
84 | - && $model->load(Yii::$app->request->post())) | |
85 | - { | |
86 | - $model->save(); | |
87 | - $page_lang->page_id = $model->page_id; | |
88 | - $page_lang->lang_id = 1; | |
89 | - $page_lang->save(); | |
90 | - | |
65 | + | |
66 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
91 | 67 | return $this->redirect(['view', 'id' => $model->page_id]); |
92 | - } | |
93 | - else | |
94 | - { | |
68 | + } else { | |
95 | 69 | return $this->render('create', [ |
96 | 70 | 'model' => $model, |
97 | - 'page_lang' => $page_lang, | |
98 | 71 | ]); |
99 | 72 | } |
100 | 73 | } |
... | ... | @@ -108,14 +81,12 @@ class PageController extends Controller |
108 | 81 | public function actionUpdate($id) |
109 | 82 | { |
110 | 83 | $model = $this->findModel($id); |
111 | - $page_lang = PageLang::find()->where(['page_id' => $id, 'lang_id' => 1])->one(); | |
112 | 84 | |
113 | 85 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
114 | 86 | return $this->redirect(['view', 'id' => $model->page_id]); |
115 | 87 | } else { |
116 | 88 | return $this->render('update', [ |
117 | 89 | 'model' => $model, |
118 | - 'page_lang' => $page_lang, | |
119 | 90 | ]); |
120 | 91 | } |
121 | 92 | } | ... | ... |
backend/controllers/Termin_langController.php
... | ... | @@ -16,8 +16,12 @@ use common\models\TerminOption; |
16 | 16 | */ |
17 | 17 | class Termin_langController extends Controller |
18 | 18 | { |
19 | + var $lang_id = 1; | |
20 | + | |
19 | 21 | public function behaviors() |
20 | 22 | { |
23 | + $this->castyl(); | |
24 | + | |
21 | 25 | return [ |
22 | 26 | 'verbs' => [ |
23 | 27 | 'class' => VerbFilter::className(), |
... | ... | @@ -27,14 +31,21 @@ class Termin_langController extends Controller |
27 | 31 | ], |
28 | 32 | ]; |
29 | 33 | } |
34 | + | |
35 | + public function castyl() | |
36 | + { | |
37 | + $this->lang_id = isset ($_GET['lang_id']) ? $_GET['lang_id'] : 1; | |
38 | + } | |
30 | 39 | |
31 | 40 | /** |
32 | 41 | * Lists all TerminLang models. |
33 | 42 | * @return mixed |
34 | 43 | */ |
35 | 44 | public function actionIndex() |
36 | - { | |
45 | + { | |
37 | 46 | $searchModel = new TerminLangSearch(); |
47 | + $searchModel->lang_id = $this->lang_id; | |
48 | + | |
38 | 49 | $dataProvider = $searchModel->search(Yii::$app->request->queryParams); |
39 | 50 | |
40 | 51 | return $this->render('index', [ |
... | ... | @@ -52,7 +63,7 @@ class Termin_langController extends Controller |
52 | 63 | public function actionView($termin_id) |
53 | 64 | { |
54 | 65 | return $this->render('view', [ |
55 | - 'model' => $this->findModel($termin_id, $lang_id), | |
66 | + 'model' => $this->findModel($termin_id, $this->lang_id), | |
56 | 67 | ]); |
57 | 68 | } |
58 | 69 | |
... | ... | @@ -117,9 +128,9 @@ class Termin_langController extends Controller |
117 | 128 | * @param integer $lang_id |
118 | 129 | * @return mixed |
119 | 130 | */ |
120 | - public function actionUpdate($termin_id, $lang_id) | |
131 | + public function actionUpdate($termin_id) | |
121 | 132 | { |
122 | - $model = $this->findModel($termin_id, $lang_id); | |
133 | + $model = $this->findModel($termin_id, $this->lang_id); | |
123 | 134 | |
124 | 135 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
125 | 136 | return $this->redirect(['view', 'termin_id' => $model->termin_id, 'lang_id' => $model->lang_id]); |
... | ... | @@ -137,9 +148,9 @@ class Termin_langController extends Controller |
137 | 148 | * @param integer $lang_id |
138 | 149 | * @return mixed |
139 | 150 | */ |
140 | - public function actionDelete($termin_id, $lang_id) | |
151 | + public function actionDelete($termin_id) | |
141 | 152 | { |
142 | - $this->findModel($termin_id, $lang_id)->delete(); | |
153 | + $this->findModel($termin_id, $this->lang_id)->delete(); | |
143 | 154 | |
144 | 155 | return $this->redirect(['index']); |
145 | 156 | } |
... | ... | @@ -152,9 +163,9 @@ class Termin_langController extends Controller |
152 | 163 | * @return TerminLang the loaded model |
153 | 164 | * @throws NotFoundHttpException if the model cannot be found |
154 | 165 | */ |
155 | - protected function findModel($termin_id, $lang_id) | |
166 | + protected function findModel($termin_id) | |
156 | 167 | { |
157 | - if (($model = TerminLang::findOne(['termin_id' => $termin_id, 'lang_id' => $lang_id])) !== null) { | |
168 | + if (($model = TerminLang::findOne(['termin_id' => $termin_id, 'lang_id' => $this->lang_id])) !== null) { | |
158 | 169 | return $model; |
159 | 170 | } else { |
160 | 171 | throw new NotFoundHttpException('The requested page does not exist.'); | ... | ... |
1 | +common/messages/1/field.php<?php | |
2 | + | |
3 | +namespace backend\models; | |
4 | + | |
5 | +use Yii; | |
6 | +use yii\base\Model; | |
7 | +use yii\data\ActiveDataProvider; | |
8 | +use common\models\Page; | |
9 | + | |
10 | +/** | |
11 | + * SearchPage represents the model behind the search form about `common\models\Page`. | |
12 | + */ | |
13 | +class SearchPage extends Page | |
14 | +{ | |
15 | + /** | |
16 | + * @inheritdoc | |
17 | + */ | |
18 | + public function rules() | |
19 | + { | |
20 | + return [ | |
21 | + [['page_id', 'template_id', 'image_id', 'show'], 'integer'], | |
22 | + [['date_add'], 'safe'], | |
23 | + ]; | |
24 | + } | |
25 | + | |
26 | + /** | |
27 | + * @inheritdoc | |
28 | + */ | |
29 | + public function scenarios() | |
30 | + { | |
31 | + // bypass scenarios() implementation in the parent class | |
32 | + return Model::scenarios(); | |
33 | + } | |
34 | + | |
35 | + /** | |
36 | + * Creates data provider instance with search query applied | |
37 | + * | |
38 | + * @param array $params | |
39 | + * | |
40 | + * @return ActiveDataProvider | |
41 | + */ | |
42 | + public function search($params) | |
43 | + { | |
44 | + $query = Page::find(); | |
45 | + | |
46 | + $dataProvider = new ActiveDataProvider([ | |
47 | + 'query' => $query, | |
48 | + ]); | |
49 | + | |
50 | + $this->load($params); | |
51 | + | |
52 | + if (!$this->validate()) { | |
53 | + // uncomment the following line if you do not want to return any records when validation fails | |
54 | + // $query->where('0=1'); | |
55 | + return $dataProvider; | |
56 | + } | |
57 | + | |
58 | + $query->andFilterWhere([ | |
59 | + 'page_id' => $this->page_id, | |
60 | + 'date_add' => $this->date_add, | |
61 | + 'template_id' => $this->template_id, | |
62 | + 'image_id' => $this->image_id, | |
63 | + 'show' => $this->show, | |
64 | + ]); | |
65 | + | |
66 | + return $dataProvider; | |
67 | + } | |
68 | +} | ... | ... |
backend/models/SearchPage.php
... | ... | @@ -2,11 +2,11 @@ |
2 | 2 | |
3 | 3 | namespace backend\models; |
4 | 4 | |
5 | -use Yii; | |
6 | 5 | use yii\base\Model; |
7 | 6 | use yii\data\ActiveDataProvider; |
8 | 7 | use common\models\Page; |
9 | 8 | |
9 | + | |
10 | 10 | /** |
11 | 11 | * SearchPage represents the model behind the search form about `common\models\Page`. |
12 | 12 | */ |
... | ... | @@ -18,7 +18,7 @@ class SearchPage extends Page |
18 | 18 | public function rules() |
19 | 19 | { |
20 | 20 | return [ |
21 | - [['page_id', 'image_id', 'show'], 'integer'], | |
21 | + [['page_id', 'template_id', 'image_id', 'show'], 'integer'], | |
22 | 22 | [['date_add'], 'safe'], |
23 | 23 | ]; |
24 | 24 | } |
... | ... | @@ -32,6 +32,7 @@ class SearchPage extends Page |
32 | 32 | return Model::scenarios(); |
33 | 33 | } |
34 | 34 | |
35 | + | |
35 | 36 | /** |
36 | 37 | * Creates data provider instance with search query applied |
37 | 38 | * |
... | ... | @@ -40,10 +41,9 @@ class SearchPage extends Page |
40 | 41 | * @return ActiveDataProvider |
41 | 42 | */ |
42 | 43 | public function search($params) |
43 | - { | |
44 | - $query = self::getAll(Yii::$app->request->get()); | |
45 | - //$query = Page::find(); | |
46 | - //->joinWith('pagelang'); | |
44 | + { | |
45 | + $query = Page::find(); | |
46 | + | |
47 | 47 | $dataProvider = new ActiveDataProvider([ |
48 | 48 | 'query' => $query, |
49 | 49 | ]); |
... | ... | @@ -57,47 +57,13 @@ class SearchPage extends Page |
57 | 57 | } |
58 | 58 | |
59 | 59 | $query->andFilterWhere([ |
60 | - $this->addCondition($query, 'title'), | |
61 | - | |
60 | + 'page_id' => $this->page_id, | |
61 | + 'date_add' => $this->date_add, | |
62 | + 'template_id' => $this->template_id, | |
63 | + 'image_id' => $this->image_id, | |
64 | + 'show' => $this->show, | |
62 | 65 | ]); |
63 | 66 | |
64 | 67 | return $dataProvider; |
65 | 68 | } |
66 | - | |
67 | - | |
68 | - static function getList (array $param = array ()) | |
69 | - { | |
70 | - $sql = ' | |
71 | - SELECT | |
72 | - `page`.date_add, `page`.`show`, | |
73 | - `page_lang`.* | |
74 | - FROM `page` | |
75 | - LEFT JOIN `page_lang` ON `page_lang`.page_id = `page`.page_id | |
76 | - AND `page_lang`.lang_id = '.(int)$param['lang_id']; | |
77 | - | |
78 | - $WHERE = array (); | |
79 | - | |
80 | - if (isset ($param['page_id'])) | |
81 | - { | |
82 | - $WHERE[] = '`page_lang`.page_id = '.(int)$param['page_id']; | |
83 | - } | |
84 | - | |
85 | - if (isset ($param['date_add'])) | |
86 | - { | |
87 | - $WHERE[] = '`page`.date_add = "'.(int)$param['page_id'].'"'; | |
88 | - } | |
89 | - | |
90 | - if (isset ($param['show'])) | |
91 | - { | |
92 | - $WHERE[] = '`page`.show = "'.(int)$param['show'].'"'; | |
93 | - } | |
94 | - | |
95 | - if (! empty ($WHERE)) | |
96 | - { | |
97 | - $sql .= ' WHERE '.implode (' AND ', $WHERE); | |
98 | - } | |
99 | - | |
100 | - return $sql; | |
101 | - } | |
102 | - | |
103 | 69 | } | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\ActiveForm; | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model common\models\Page */ | |
8 | +/* @var $form yii\widgets\ActiveForm */ | |
9 | +?> | |
10 | + | |
11 | +<div class="page-form"> | |
12 | + | |
13 | + <?php $form = ActiveForm::begin(); ?> | |
14 | + | |
15 | + <?= $form->field($model, 'date_add')->textInput() ?> | |
16 | + | |
17 | + <?= $form->field($model, 'template_id')->textInput() ?> | |
18 | + | |
19 | + <?= $form->field($model, 'image_id')->textInput() ?> | |
20 | + | |
21 | + <?= $form->field($model, 'show')->textInput() ?> | |
22 | + | |
23 | + <div class="form-group"> | |
24 | + <?= Html::submitButton($model->isNewRecord ? Yii::t('field', 'Create') : Yii::t('field', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
25 | + </div> | |
26 | + | |
27 | + <?php ActiveForm::end(); ?> | |
28 | + | |
29 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\ActiveForm; | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model backend\models\SearchPage */ | |
8 | +/* @var $form yii\widgets\ActiveForm */ | |
9 | +?> | |
10 | + | |
11 | +<div class="page-search"> | |
12 | + | |
13 | + <?php $form = ActiveForm::begin([ | |
14 | + 'action' => ['index'], | |
15 | + 'method' => 'get', | |
16 | + ]); ?> | |
17 | + | |
18 | + <?= $form->field($model, 'page_id') ?> | |
19 | + | |
20 | + <?= $form->field($model, 'date_add') ?> | |
21 | + | |
22 | + <?= $form->field($model, 'template_id') ?> | |
23 | + | |
24 | + <?= $form->field($model, 'image_id') ?> | |
25 | + | |
26 | + <?= $form->field($model, 'show') ?> | |
27 | + | |
28 | + <div class="form-group"> | |
29 | + <?= Html::submitButton(Yii::t('field', 'Search'), ['class' => 'btn btn-primary']) ?> | |
30 | + <?= Html::resetButton(Yii::t('field', 'Reset'), ['class' => 'btn btn-default']) ?> | |
31 | + </div> | |
32 | + | |
33 | + <?php ActiveForm::end(); ?> | |
34 | + | |
35 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | + | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model common\models\Page */ | |
8 | + | |
9 | +$this->title = Yii::t('field', 'Create Page'); | |
10 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('field', 'Pages'), 'url' => ['index']]; | |
11 | +$this->params['breadcrumbs'][] = $this->title; | |
12 | +?> | |
13 | +<div class="page-create"> | |
14 | + | |
15 | + <h1><?= Html::encode($this->title) ?></h1> | |
16 | + | |
17 | + <?= $this->render('_form', [ | |
18 | + 'model' => $model, | |
19 | + ]) ?> | |
20 | + | |
21 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\grid\GridView; | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $searchModel backend\models\SearchPage */ | |
8 | +/* @var $dataProvider yii\data\ActiveDataProvider */ | |
9 | + | |
10 | +$this->title = Yii::t('field', 'Pages'); | |
11 | +$this->params['breadcrumbs'][] = $this->title; | |
12 | +?> | |
13 | +<div class="page-index"> | |
14 | + | |
15 | + <h1><?= Html::encode($this->title) ?></h1> | |
16 | + <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | |
17 | + | |
18 | + <p> | |
19 | + <?= Html::a(Yii::t('field', 'Create Page'), ['create'], ['class' => 'btn btn-success']) ?> | |
20 | + </p> | |
21 | + | |
22 | + <?= GridView::widget([ | |
23 | + 'dataProvider' => $dataProvider, | |
24 | + 'filterModel' => $searchModel, | |
25 | + 'columns' => [ | |
26 | + ['class' => 'yii\grid\SerialColumn'], | |
27 | + | |
28 | + 'page_id', | |
29 | + 'date_add', | |
30 | + 'template_id', | |
31 | + 'image_id', | |
32 | + 'show', | |
33 | + | |
34 | + ['class' => 'yii\grid\ActionColumn'], | |
35 | + ], | |
36 | + ]); ?> | |
37 | + | |
38 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | + | |
5 | +/* @var $this yii\web\View */ | |
6 | +/* @var $model common\models\Page */ | |
7 | + | |
8 | +$this->title = Yii::t('field', 'Update {modelClass}: ', [ | |
9 | + 'modelClass' => 'Page', | |
10 | +]) . ' ' . $model->page_id; | |
11 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('field', 'Pages'), 'url' => ['index']]; | |
12 | +$this->params['breadcrumbs'][] = ['label' => $model->page_id, 'url' => ['view', 'id' => $model->page_id]]; | |
13 | +$this->params['breadcrumbs'][] = Yii::t('field', 'Update'); | |
14 | +?> | |
15 | +<div class="page-update"> | |
16 | + | |
17 | + <h1><?= Html::encode($this->title) ?></h1> | |
18 | + | |
19 | + <?= $this->render('_form', [ | |
20 | + 'model' => $model, | |
21 | + ]) ?> | |
22 | + | |
23 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\DetailView; | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model common\models\Page */ | |
8 | + | |
9 | +$this->title = $model->page_id; | |
10 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('field', 'Pages'), 'url' => ['index']]; | |
11 | +$this->params['breadcrumbs'][] = $this->title; | |
12 | +?> | |
13 | +<div class="page-view"> | |
14 | + | |
15 | + <h1><?= Html::encode($this->title) ?></h1> | |
16 | + | |
17 | + <p> | |
18 | + <?= Html::a(Yii::t('field', 'Update'), ['update', 'id' => $model->page_id], ['class' => 'btn btn-primary']) ?> | |
19 | + <?= Html::a(Yii::t('field', 'Delete'), ['delete', 'id' => $model->page_id], [ | |
20 | + 'class' => 'btn btn-danger', | |
21 | + 'data' => [ | |
22 | + 'confirm' => Yii::t('field', 'Are you sure you want to delete this item?'), | |
23 | + 'method' => 'post', | |
24 | + ], | |
25 | + ]) ?> | |
26 | + </p> | |
27 | + | |
28 | + <?= DetailView::widget([ | |
29 | + 'model' => $model, | |
30 | + 'attributes' => [ | |
31 | + 'page_id', | |
32 | + 'date_add', | |
33 | + 'template_id', | |
34 | + 'image_id', | |
35 | + 'show', | |
36 | + ], | |
37 | + ]) ?> | |
38 | + | |
39 | +</div> | ... | ... |
backend/views/page/_form.php
... | ... | @@ -2,7 +2,6 @@ |
2 | 2 | |
3 | 3 | use yii\helpers\Html; |
4 | 4 | use yii\widgets\ActiveForm; |
5 | -use yii\jui\DatePicker; | |
6 | 5 | |
7 | 6 | /* @var $this yii\web\View */ |
8 | 7 | /* @var $model common\models\Page */ |
... | ... | @@ -13,28 +12,35 @@ use yii\jui\DatePicker; |
13 | 12 | |
14 | 13 | <?php $form = ActiveForm::begin(); ?> |
15 | 14 | |
16 | - <h2>Common</h2> | |
15 | + <h2><?= Yii::t('field', 'common'); ?></h2> | |
17 | 16 | |
18 | - <?= $form->field($model, 'date_add')->widget(DatePicker::className(), ['dateFormat' => 'yyyy-MM-dd']) ?> | |
19 | - | |
20 | - <? //$form->field($model, 'image_id')->textInput() ?> | |
17 | + <?= $form->field($model, 'date_add')->textInput() ?> | |
21 | 18 | |
22 | - <?= $form->field($model, 'show')->dropDownList(['1' => 'Показать', '0' => 'Спрятать']) ?> | |
23 | - | |
24 | - <h2>Lang</h2> | |
25 | - | |
26 | - <?= $form->field($page_lang, 'title')->textInput() ?> | |
27 | - | |
28 | - <?= $form->field($page_lang, 'meta_title')->textarea(['rows' => 1]) ?> | |
29 | - | |
30 | - <?= $form->field($page_lang, 'meta_description')->textarea(['rows' => 1]) ?> | |
31 | - | |
32 | - <?= $form->field($page_lang, 'text')->textarea(['rows' => 6]) ?> | |
19 | + <?= $form->field($model, 'template_id')->textInput() ?> | |
20 | + | |
21 | + <?= $form->field($model, 'image_id')->textInput() ?> | |
33 | 22 | |
34 | - <?= $form->field($page_lang, 'page_alias')->textInput() ?> | |
23 | + <?= $form->field($model, 'show')->textInput() ?> | |
35 | 24 | |
25 | + <h2><?= Yii::t('field', 'lang'); ?></h2> | |
26 | + | |
27 | + <?= $form->field($model, 'title')->textInput() ?> | |
28 | + | |
29 | + <?= $form->field($model, 'meta_title')->textarea() ?> | |
30 | + | |
31 | + <?= $form->field($model, 'meta_description')->textarea() ?> | |
32 | + | |
33 | + <?= $form->field($model, 'text')->textarea(['row' => 4]) ?> | |
34 | + | |
35 | + <?= $form->field($model, 'page_alias')->textInput() ?> | |
36 | + | |
36 | 37 | <div class="form-group"> |
37 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
38 | + <?= Html::submitButton( | |
39 | + $model->isNewRecord ? | |
40 | + Yii::t('action', 'add') : | |
41 | + Yii::t('action', 'update'), | |
42 | + ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary'] | |
43 | + ) ?> | |
38 | 44 | </div> |
39 | 45 | |
40 | 46 | <?php ActiveForm::end(); ?> | ... | ... |
backend/views/page/_search.php
backend/views/page/create.php
backend/views/page/index.php
... | ... | @@ -12,24 +12,24 @@ $this->params['breadcrumbs'][] = $this->title; |
12 | 12 | ?> |
13 | 13 | <div class="page-index"> |
14 | 14 | |
15 | - <h1><?= Html::encode($this->title) ?></h1> | |
15 | + <h1><?= Html::encode($this->title) ?></h1> | |
16 | + <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | |
16 | 17 | |
17 | 18 | <p> |
18 | - <?= Html::a('Create Page', ['create'], ['class' => 'btn btn-success']) ?> | |
19 | + <?= Html::a(Yii::t('field', 'date_add'), ['create'], ['class' => 'btn btn-success']) ?> | |
19 | 20 | </p> |
20 | - | |
21 | + | |
21 | 22 | <?= GridView::widget([ |
22 | 23 | 'dataProvider' => $dataProvider, |
23 | 24 | 'filterModel' => $searchModel, |
24 | - //'filterModel' => ['title' => 1], | |
25 | 25 | 'columns' => [ |
26 | - | |
27 | 26 | ['class' => 'yii\grid\SerialColumn'], |
28 | 27 | |
29 | - 'page_id' , | |
28 | + 'page_id', | |
30 | 29 | 'date_add', |
31 | - //'title', | |
32 | - 'show', | |
30 | + 'title', | |
31 | + 'template_id', | |
32 | + 'show', | |
33 | 33 | |
34 | 34 | ['class' => 'yii\grid\ActionColumn'], |
35 | 35 | ], | ... | ... |
backend/views/page/update.php
... | ... | @@ -5,10 +5,10 @@ use yii\helpers\Html; |
5 | 5 | /* @var $this yii\web\View */ |
6 | 6 | /* @var $model common\models\Page */ |
7 | 7 | |
8 | -$this->title = 'Update Page: ' . ' ' . $model->page_id; | |
9 | -$this->params['breadcrumbs'][] = ['label' => 'Pages', 'url' => ['index']]; | |
10 | -$this->params['breadcrumbs'][] = ['label' => $model->page_id, 'url' => ['view', 'id' => $model->page_id]]; | |
11 | -$this->params['breadcrumbs'][] = 'Update'; | |
8 | +$this->title = Yii::t('action', 'edit').': ' . ' ' . $model->title; | |
9 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('field', 'page'), 'url' => ['index']]; | |
10 | +$this->params['breadcrumbs'][] = ['label' => $model->page_id, 'url' => [Yii::t('action', 'view'), 'id' => $model->page_id]]; | |
11 | +$this->params['breadcrumbs'][] = Yii::t('action', 'update'); | |
12 | 12 | ?> |
13 | 13 | <div class="page-update"> |
14 | 14 | |
... | ... | @@ -16,7 +16,6 @@ $this->params['breadcrumbs'][] = 'Update'; |
16 | 16 | |
17 | 17 | <?= $this->render('_form', [ |
18 | 18 | 'model' => $model, |
19 | - 'page_lang' =>$page_lang, | |
20 | 19 | ]) ?> |
21 | 20 | |
22 | 21 | </div> | ... | ... |
backend/views/page/view.php
... | ... | @@ -2,13 +2,14 @@ |
2 | 2 | |
3 | 3 | use yii\helpers\Html; |
4 | 4 | use yii\widgets\DetailView; |
5 | +use yii\data\Pagination; | |
5 | 6 | |
6 | 7 | /* @var $this yii\web\View */ |
7 | 8 | /* @var $model common\models\Page */ |
8 | - | |
9 | + | |
9 | 10 | $this->title = $model->page_id; |
10 | -$this->params['breadcrumbs'][] = ['label' => 'Pages', 'url' => ['index']]; | |
11 | -$this->params['breadcrumbs'][] = $this->title; | |
11 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('field', 'n, page', ['n' => 1]), 'url' => ['index']]; | |
12 | +$this->params['breadcrumbs'][] = Yii::t('field', 'n, page', ['n' => 'few']); | |
12 | 13 | ?> |
13 | 14 | <div class="page-view"> |
14 | 15 | |
... | ... | @@ -30,6 +31,7 @@ $this->params['breadcrumbs'][] = $this->title; |
30 | 31 | 'attributes' => [ |
31 | 32 | 'page_id', |
32 | 33 | 'date_add', |
34 | + 'template_id', | |
33 | 35 | 'image_id', |
34 | 36 | 'show', |
35 | 37 | ], | ... | ... |
backend/views/termin_lang/_form.php
... | ... | @@ -12,7 +12,7 @@ use yii\widgets\ActiveForm; |
12 | 12 | |
13 | 13 | <?php $form = ActiveForm::begin(); ?> |
14 | 14 | |
15 | - <?= $form->field($termin_lang, 'termin_title')->textInput(['maxlength' => true]) ?> | |
15 | + <?= $form->field($termin_lang, 'termin_title')->textInput(['maxlength' => 256]) ?> | |
16 | 16 | |
17 | 17 | <div class="form-group"> |
18 | 18 | <?= Html::submitButton($termin_lang->isNewRecord ? 'Create' : 'Update', ['class' => $termin_lang->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | ... | ... |
backend/views/termin_lang/create.php
... | ... | @@ -6,7 +6,7 @@ use yii\helpers\Html; |
6 | 6 | /* @var $this yii\web\View */ |
7 | 7 | /* @var $model common\models\TerminLang */ |
8 | 8 | |
9 | -$this->title = 'Create Termin Lang'; | |
9 | +$this->title = 'Добавить Термин'; | |
10 | 10 | $this->params['breadcrumbs'][] = ['label' => 'Termin Langs', 'url' => ['index']]; |
11 | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | 12 | ?> | ... | ... |
backend/views/termin_lang/index.php
... | ... | @@ -7,7 +7,7 @@ use yii\grid\GridView; |
7 | 7 | /* @var $searchModel backend\models\TerminLangSearch */ |
8 | 8 | /* @var $dataProvider yii\data\ActiveDataProvider */ |
9 | 9 | |
10 | -$this->title = 'Termin Langs'; | |
10 | +$this->title = 'Термин'; | |
11 | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | 12 | ?> |
13 | 13 | <div class="termin-lang-index"> | ... | ... |
backend/views/termin_lang/update.php
... | ... | @@ -5,7 +5,7 @@ use yii\helpers\Html; |
5 | 5 | /* @var $this yii\web\View */ |
6 | 6 | /* @var $model common\models\TerminLang */ |
7 | 7 | |
8 | -$this->title = 'Update Termin Lang: ' . ' ' . $model->termin_id; | |
8 | +$this->title = 'Редактировать Термин: ' . ' ' . $model->termin_id; | |
9 | 9 | $this->params['breadcrumbs'][] = ['label' => 'Termin Langs', 'url' => ['index']]; |
10 | 10 | $this->params['breadcrumbs'][] = ['label' => $model->termin_id, 'url' => ['view', 'termin_id' => $model->termin_id, 'lang_id' => $model->lang_id]]; |
11 | 11 | $this->params['breadcrumbs'][] = 'Update'; |
... | ... | @@ -15,7 +15,7 @@ $this->params['breadcrumbs'][] = 'Update'; |
15 | 15 | <h1><?= Html::encode($this->title) ?></h1> |
16 | 16 | |
17 | 17 | <?= $this->render('_form', [ |
18 | - 'model' => $model, | |
18 | + 'termin_lang' => $model, | |
19 | 19 | ]) ?> |
20 | 20 | |
21 | 21 | </div> | ... | ... |
backend/views/termin_lang/view.php
... | ... | @@ -6,8 +6,8 @@ use yii\widgets\DetailView; |
6 | 6 | /* @var $this yii\web\View */ |
7 | 7 | /* @var $model common\models\TerminLang */ |
8 | 8 | |
9 | -$this->title = $model->termin_id; | |
10 | -$this->params['breadcrumbs'][] = ['label' => 'Termin Langs', 'url' => ['index']]; | |
9 | +$this->title = 'Термин: '.$model->termin_title; | |
10 | +$this->params['breadcrumbs'][] = ['label' => 'Термин', 'url' => ['index']]; | |
11 | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | 12 | ?> |
13 | 13 | <div class="termin-lang-view"> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace common\components; | |
4 | + | |
5 | +use Yii; | |
6 | +use yii\web\Request; | |
7 | +use common\models\Language; | |
8 | + | |
9 | +class LangRequest extends Request | |
10 | +{ | |
11 | + private $_lang_url; | |
12 | + | |
13 | + public function getLangUrl() | |
14 | + { | |
15 | + if ($this->_lang_url === null) | |
16 | + { | |
17 | + $this->_lang_url = $this->getUrl(); | |
18 | + | |
19 | + $url_list = explode ('/', $this->_lang_url); | |
20 | + | |
21 | + $lang_url = isset ($url_list[1]) ? $url_list[1] : null; | |
22 | + | |
23 | + Language::setCurrent($lang_url); | |
24 | + | |
25 | + if ($lang_url !== null && $lang_url === Language::getCurrent()->lang_code | |
26 | + && strpos($this->_lang_url, Language::getCurrent()->lang_code) === 1) | |
27 | + { | |
28 | + $this->_lang_url = substr ($this->_lang_url, strlen (Language::getCurrent()->lang_code) + 1); | |
29 | + } | |
30 | + } | |
31 | + | |
32 | + return $this->_lang_url; | |
33 | + } | |
34 | + | |
35 | + protected function resolvePathInfo() | |
36 | + { | |
37 | + $pathInfo = $this->getLangUrl(); | |
38 | + | |
39 | + if (($pos = strpos ($pathInfo, '?')) !== false) | |
40 | + { | |
41 | + $pathInfo = substr ($pathInfo, 0, $pos); | |
42 | + } | |
43 | + | |
44 | + $pathInfo = urldecode ($pathInfo); | |
45 | + | |
46 | + // try to encode in UTF8 if not so | |
47 | + // http://w3.org/International/questions/qa-forms-utf-8.html | |
48 | + if (! preg_match ('%^(?: | |
49 | + [\x09\x0A\x0D\x20-\x7E] # ASCII | |
50 | + | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | |
51 | + | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs | |
52 | + | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte | |
53 | + | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates | |
54 | + | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 | |
55 | + | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 | |
56 | + | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 | |
57 | + )*$%xs', $pathInfo) | |
58 | + ) | |
59 | + { | |
60 | + $pathInfo = utf8_encode($pathInfo); | |
61 | + } | |
62 | + | |
63 | + $scriptUrl = $this->getScriptUrl(); | |
64 | + $baseUrl = $this->getBaseUrl(); | |
65 | + | |
66 | + if (strpos($pathInfo, $scriptUrl) === 0) | |
67 | + { | |
68 | + $pathInfo = substr($pathInfo, strlen($scriptUrl)); | |
69 | + } | |
70 | + else if ($baseUrl === '' || strpos($pathInfo, $baseUrl) === 0) | |
71 | + { | |
72 | + $pathInfo = substr($pathInfo, strlen($baseUrl)); | |
73 | + } | |
74 | + elseif (isset ($_SERVER['PHP_SELF']) && strpos ($_SERVER['PHP_SELF'], $scriptUrl) === 0) | |
75 | + { | |
76 | + $pathInfo = substr($_SERVER['PHP_SELF'], strlen($scriptUrl)); | |
77 | + } | |
78 | + else | |
79 | + { | |
80 | + throw new InvalidConfigException('Unable to determine the path info of the current request.'); | |
81 | + } | |
82 | + | |
83 | + if ($pathInfo[0] === '/') | |
84 | + { | |
85 | + $pathInfo = substr ($pathInfo, 1); | |
86 | + } | |
87 | + | |
88 | + return (string) $pathInfo; | |
89 | + } | |
90 | +} | |
0 | 91 | \ No newline at end of file | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace common\components; | |
4 | + | |
5 | +use yii\web\UrlManager; | |
6 | +use common\models\Language; | |
7 | + | |
8 | +class LangUrlManager extends UrlManager | |
9 | +{ | |
10 | + public function createUrl ($params) | |
11 | + { | |
12 | + if (isset ($params['lang_id'])) | |
13 | + { | |
14 | + //Если указан идентификатор языка, то делаем попытку найти язык в БД, | |
15 | + //иначе работаем с языком по умолчанию | |
16 | + if (($lang_code = Language::findOne($params['lang_id'])) === null) | |
17 | + { | |
18 | + $lang_code = Language::getDefaultLang(); | |
19 | + } | |
20 | + | |
21 | + unset ($params['lang_id']); | |
22 | + | |
23 | + } | |
24 | + else | |
25 | + { | |
26 | + //Если не указан параметр языка, то работаем с текущим языком | |
27 | + $lang_code = Language::getCurrent(); | |
28 | + } | |
29 | + | |
30 | + //Получаем сформированный URL(без префикса идентификатора языка) | |
31 | + $url = parent::createUrl($params); | |
32 | + | |
33 | + // Добавляем к URL префикс - буквенный идентификатор языка | |
34 | + | |
35 | + return $url == '/' ? '/'.$url : ($lang_code->is_default == 1 ? $url : '/'.$lang_code->lang_code.$url); | |
36 | + } | |
37 | +} | |
0 | 38 | \ No newline at end of file | ... | ... |
common/config/main.php
... | ... | @@ -5,5 +5,29 @@ return [ |
5 | 5 | 'cache' => [ |
6 | 6 | 'class' => 'yii\caching\FileCache', |
7 | 7 | ], |
8 | + 'urlManager' => [ | |
9 | + 'enablePrettyUrl' => true, | |
10 | + 'showScriptName' => false, | |
11 | + 'class'=> 'common\components\LangUrlManager', | |
12 | + 'rules'=>[ | |
13 | + '/' => 'site/index', | |
14 | + '<controller:\w+>/<action:\w+>/*'=>'<controller>/<action>', | |
15 | + ] | |
16 | + ], | |
17 | + 'request' => [ | |
18 | + 'class' => 'common\components\LangRequest' | |
19 | + ], | |
20 | + 'i18n' => [ | |
21 | + 'translations' => [ | |
22 | + '*' => [ | |
23 | + 'class' => 'yii\i18n\PhpMessageSource', | |
24 | + 'basePath' => $_SERVER['DOCUMENT_ROOT'].'/common/messages', | |
25 | + 'fileMap' => [ | |
26 | + 'app' => 'app.php', | |
27 | + 'app/error' => 'error.php', | |
28 | + ], | |
29 | + ], | |
30 | + ], | |
31 | + ], | |
8 | 32 | ], |
9 | 33 | ]; | ... | ... |
1 | +<?php | |
2 | + | |
3 | +return [ | |
4 | + 'page|' => 'Сторінка', | |
5 | + 'date_add' => 'Дата додання', | |
6 | + 'template' => 'Шаблон', | |
7 | + 'image' => 'Картинка', | |
8 | + 'show' => 'Відображати', | |
9 | + 'title' => 'Заголовок', | |
10 | + 'meta_title' => 'Meta Title', | |
11 | + 'meta_description' => 'Meta Description', | |
12 | + 'text' => 'Текст', | |
13 | + 'page_alias' => 'alias', | |
14 | + 'lang_id' => 'ID мови', | |
15 | + 'common' => 'Загальне', | |
16 | + 'lang' => 'Мовні змінні', | |
17 | +]; | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace common\models; | |
4 | + | |
5 | +use Yii; | |
6 | + | |
7 | +/** | |
8 | + * This is the model class for table "language". | |
9 | + * | |
10 | + * @property integer $language_id | |
11 | + * @property string $lang_code | |
12 | + */ | |
13 | +class Language extends \yii\db\ActiveRecord | |
14 | +{ | |
15 | + | |
16 | + //Переменная, для хранения текущего объекта языка | |
17 | + static $current = null; | |
18 | + | |
19 | + //Получение текущего объекта языка | |
20 | + static function getCurrent() | |
21 | + { | |
22 | + if (self::$current === null) | |
23 | + { | |
24 | + self::$current = self::getDefaultLang(); | |
25 | + } | |
26 | + | |
27 | + return self::$current; | |
28 | + } | |
29 | + | |
30 | + //Установка текущего объекта языка и локаль пользователя | |
31 | + static function setCurrent ($lang_code = null) | |
32 | + { | |
33 | + $language = self::getLangByUrl ($lang_code); | |
34 | + self::$current = ($language === null) ? self::getDefaultLang() : $language; | |
35 | + // задаем | |
36 | + Yii::$app->language = self::$current->lang_code; | |
37 | + Yii::$app->lang_id = self::$current->language_id; | |
38 | + } | |
39 | + | |
40 | + //Получения объекта языка по умолчанию | |
41 | + static function getDefaultLang() | |
42 | + { | |
43 | + return Language::find()->where('`is_default` = :default', [':default' => 1])->one(); | |
44 | + } | |
45 | + | |
46 | + //Получения объекта языка по буквенному идентификатору | |
47 | + static function getLangByUrl ($lang_code = null) | |
48 | + { | |
49 | + if ($lang_code === null) | |
50 | + { | |
51 | + return null; | |
52 | + } | |
53 | + else | |
54 | + { | |
55 | + $language = Language::find()->where('lang_code = :what', [':what' => $lang_code])->one(); | |
56 | + return $language === null ? null : $language; | |
57 | + } | |
58 | + } | |
59 | + | |
60 | + /** | |
61 | + * @inheritdoc | |
62 | + */ | |
63 | + public static function tableName() | |
64 | + { | |
65 | + return 'language'; | |
66 | + } | |
67 | + | |
68 | + /** | |
69 | + * @inheritdoc | |
70 | + */ | |
71 | + public function rules() | |
72 | + { | |
73 | + return [ | |
74 | + [['lang_code'], 'required'], | |
75 | + [['lang_code'], 'string', 'max' => 4] | |
76 | + ]; | |
77 | + } | |
78 | + | |
79 | + /** | |
80 | + * @inheritdoc | |
81 | + */ | |
82 | + public function attributeLabels() | |
83 | + { | |
84 | + return [ | |
85 | + 'language_id' => Yii::t('app/Lang', 'Language ID'), | |
86 | + 'lang_code' => Yii::t('app/Lang', 'Lang Code'), | |
87 | + ]; | |
88 | + } | |
89 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace common\models; | |
4 | + | |
5 | +use Yii; | |
6 | + | |
7 | +/** | |
8 | + * This is the model class for table "page". | |
9 | + * | |
10 | + * @property integer $page_id | |
11 | + * @property string $date_add | |
12 | + * @property integer $template_id | |
13 | + * @property integer $image_id | |
14 | + * @property integer $show | |
15 | + */ | |
16 | +class Page extends \yii\db\ActiveRecord | |
17 | +{ | |
18 | + /** | |
19 | + * @inheritdoc | |
20 | + */ | |
21 | + public static function tableName() | |
22 | + { | |
23 | + return 'page'; | |
24 | + } | |
25 | + | |
26 | + /** | |
27 | + * @inheritdoc | |
28 | + */ | |
29 | + public function rules() | |
30 | + { | |
31 | + return [ | |
32 | + [['date_add', 'template_id', 'image_id', 'show'], 'required'], | |
33 | + [['date_add'], 'safe'], | |
34 | + [['template_id', 'image_id', 'show'], 'integer'] | |
35 | + ]; | |
36 | + } | |
37 | + | |
38 | + /** | |
39 | + * @inheritdoc | |
40 | + */ | |
41 | + public function attributeLabels() | |
42 | + { | |
43 | + return [ | |
44 | + 'page_id' => Yii::t('app/Lang', 'Page ID'), | |
45 | + 'date_add' => Yii::t('app/Lang', 'Date Add'), | |
46 | + 'template_id' => Yii::t('app/Lang', 'Template ID'), | |
47 | + 'image_id' => Yii::t('app/Lang', 'Image ID'), | |
48 | + 'show' => Yii::t('app/Lang', 'Show'), | |
49 | + ]; | |
50 | + } | |
51 | +} | ... | ... |
common/models/Page.php
... | ... | @@ -3,17 +3,33 @@ |
3 | 3 | namespace common\models; |
4 | 4 | |
5 | 5 | use Yii; |
6 | +use common\models\PageLang; | |
6 | 7 | |
7 | 8 | /** |
8 | 9 | * This is the model class for table "page". |
9 | 10 | * |
10 | 11 | * @property integer $page_id |
11 | 12 | * @property string $date_add |
13 | + * @property integer $template_id | |
12 | 14 | * @property integer $image_id |
13 | 15 | * @property integer $show |
14 | 16 | */ |
15 | 17 | class Page extends \yii\db\ActiveRecord |
16 | 18 | { |
19 | + private static $getAttributeLabelCache; | |
20 | + | |
21 | + public function getAttributeLabel($attribute) | |
22 | + { | |
23 | + $class = get_class($this); | |
24 | + | |
25 | + if (!isset(self::$getAttributeLabelCache[$class][$attribute])) { | |
26 | + self::$getAttributeLabelCache[$class][$attribute] = parent::getAttributeLabel($attribute); | |
27 | + } | |
28 | + | |
29 | + return self::$getAttributeLabelCache[$class][$attribute]; | |
30 | + } | |
31 | + | |
32 | + //public $title; | |
17 | 33 | /** |
18 | 34 | * @inheritdoc |
19 | 35 | */ |
... | ... | @@ -21,6 +37,38 @@ class Page extends \yii\db\ActiveRecord |
21 | 37 | { |
22 | 38 | return 'page'; |
23 | 39 | } |
40 | + | |
41 | + // ==== EXTRA ==== | |
42 | + | |
43 | + public function getExtraField($key) | |
44 | + { | |
45 | + return PageLang::find()->where(['page_id' => $this->page_id, 'lang_id' => 1])->one()->$key; | |
46 | + } | |
47 | + | |
48 | + public function getTitle() | |
49 | + { | |
50 | + return $this->getExtraField('title'); | |
51 | + } | |
52 | + | |
53 | + public function getMeta_title() | |
54 | + { | |
55 | + return $this->getExtraField('meta_title'); | |
56 | + } | |
57 | + | |
58 | + public function getMeta_description() | |
59 | + { | |
60 | + return $this->getExtraField('meta_description'); | |
61 | + } | |
62 | + | |
63 | + public function getText() | |
64 | + { | |
65 | + return $this->getExtraField('text'); | |
66 | + } | |
67 | + | |
68 | + public function getPage_alias() | |
69 | + { | |
70 | + return $this->getExtraField('page_alias'); | |
71 | + } | |
24 | 72 | |
25 | 73 | /** |
26 | 74 | * @inheritdoc |
... | ... | @@ -28,9 +76,9 @@ class Page extends \yii\db\ActiveRecord |
28 | 76 | public function rules() |
29 | 77 | { |
30 | 78 | return [ |
31 | - [['date_add', 'image_id', 'show'], 'safe'], | |
79 | + [['date_add', 'template_id', 'image_id', 'show'], 'required'], | |
32 | 80 | [['date_add'], 'safe'], |
33 | - [['image_id', 'show'], 'integer'] | |
81 | + [['template_id', 'image_id', 'show'], 'integer'] | |
34 | 82 | ]; |
35 | 83 | } |
36 | 84 | |
... | ... | @@ -40,15 +88,18 @@ class Page extends \yii\db\ActiveRecord |
40 | 88 | public function attributeLabels() |
41 | 89 | { |
42 | 90 | return [ |
43 | - 'page_id' => 'Page ID', | |
44 | - 'date_add' => 'Date Add', | |
45 | - 'image_id' => 'Image ID', | |
46 | - 'show' => 'Show', | |
91 | + 'page_id' => Yii::t('field', 'page'), | |
92 | + 'date_add' => Yii::t('field', 'date_add'), | |
93 | + 'template_id' => Yii::t('field', 'template'), | |
94 | + 'image_id' => Yii::t('field', 'image'), | |
95 | + 'show' => Yii::t('field', 'show'), | |
96 | + | |
97 | + 'title' => Yii::t('field', 'title'), | |
98 | + 'meta_title' => Yii::t('field', 'meta_title'), | |
99 | + 'meta_description' => Yii::t('field', 'meta_description'), | |
100 | + 'text' => Yii::t('field', 'text'), | |
101 | + 'page_alias' => Yii::t('field', 'page_alias'), | |
102 | + 'lang_id' => Yii::t('field', 'lang_id'), | |
47 | 103 | ]; |
48 | - } | |
49 | - | |
50 | - public function getPagelang() | |
51 | - { | |
52 | - return $this->hasMany(PageLang::className(), ['page_id' => 'page_id']); | |
53 | - } | |
54 | -} | |
55 | 104 | \ No newline at end of file |
105 | + } | |
106 | +} | ... | ... |
common/models/PageLang.php
... | ... | @@ -8,6 +8,7 @@ use Yii; |
8 | 8 | * This is the model class for table "page_lang". |
9 | 9 | * |
10 | 10 | * @property integer $page_id |
11 | + * @property string $title | |
11 | 12 | * @property string $meta_title |
12 | 13 | * @property string $meta_description |
13 | 14 | * @property string $text |
... | ... | @@ -30,11 +31,11 @@ class PageLang extends \yii\db\ActiveRecord |
30 | 31 | public function rules() |
31 | 32 | { |
32 | 33 | return [ |
33 | - [['page_id', 'title', 'meta_title', 'meta_description', 'text', 'page_alias', 'lang_id'], 'safe'], | |
34 | + [['page_id', 'title', 'meta_title', 'meta_description', 'text', 'page_alias', 'lang_id'], 'required'], | |
34 | 35 | [['page_id', 'lang_id'], 'integer'], |
35 | 36 | [['text'], 'string'], |
36 | - [['meta_title', 'meta_description'], 'string', 'max' => 512], | |
37 | - [['page_alias'], 'string', 'max' => 256] | |
37 | + [['title', 'page_alias'], 'string', 'max' => 256], | |
38 | + [['meta_title', 'meta_description'], 'string', 'max' => 512] | |
38 | 39 | ]; |
39 | 40 | } |
40 | 41 | |
... | ... | @@ -44,18 +45,13 @@ class PageLang extends \yii\db\ActiveRecord |
44 | 45 | public function attributeLabels() |
45 | 46 | { |
46 | 47 | return [ |
47 | - 'page_id' => 'Page ID', | |
48 | - 'title' => 'title', | |
49 | - 'meta_title' => 'Meta Title', | |
50 | - 'meta_description' => 'Meta Description', | |
51 | - 'text' => 'Text', | |
52 | - 'page_alias' => 'Page Alias', | |
53 | - 'lang_id' => 'Lang ID', | |
54 | - ]; | |
55 | - } | |
56 | - | |
57 | - public function getPage() | |
58 | - { | |
59 | - return $this->hasMany(Page::className(), ['page_id' => 'page_id']); | |
48 | + 'page_id' => Yii::t('field', 'page'), | |
49 | + 'title' => Yii::t('field', 'title'), | |
50 | + 'meta_title' => Yii::t('field', 'meta_title'), | |
51 | + 'meta_description' => Yii::t('field', 'meta_description'), | |
52 | + 'text' => Yii::t('field', 'text'), | |
53 | + 'page_alias' => Yii::t('field', 'page_alias'), | |
54 | + 'lang_id' => Yii::t('field', 'lang_id'), | |
55 | + ]; | |
60 | 56 | } |
61 | 57 | } | ... | ... |
common/models/TerminLang.php
... | ... | @@ -29,7 +29,7 @@ class TerminLang extends \yii\db\ActiveRecord |
29 | 29 | return [ |
30 | 30 | //[['termin_id', 'lang_id'], 'required'], |
31 | 31 | //[['termin_id', 'lang_id'], 'integer'], |
32 | - [['termin_title'], 'string', 'max' => 256] | |
32 | + [['termin_title'], 'string'] | |
33 | 33 | ]; |
34 | 34 | } |
35 | 35 | |
... | ... | @@ -39,9 +39,9 @@ class TerminLang extends \yii\db\ActiveRecord |
39 | 39 | public function attributeLabels() |
40 | 40 | { |
41 | 41 | return [ |
42 | - 'termin_id' => 'Termin ID', | |
43 | - 'termin_title' => 'Termin Title', | |
44 | - 'lang_id' => 'Lang ID', | |
42 | + 'termin_id' => 'Термин ID', | |
43 | + 'termin_title' => 'Название', | |
44 | + 'lang_id' => 'ID языка', | |
45 | 45 | ]; |
46 | 46 | } |
47 | 47 | } | ... | ... |
artbox_db.sql renamed to db-migration/artbox_db.sql
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | -- http://www.phpmyadmin.net |
4 | 4 | -- |
5 | 5 | -- Хост: 127.0.0.1:3306 |
6 | --- Час створення: Лис 04 2015 р., 15:24 | |
6 | +-- Час створення: Лис 06 2015 р., 12:08 | |
7 | 7 | -- Версія сервера: 5.5.45 |
8 | 8 | -- Версія PHP: 5.6.12 |
9 | 9 | |
... | ... | @@ -17,7 +17,7 @@ SET time_zone = "+00:00"; |
17 | 17 | /*!40101 SET NAMES utf8 */; |
18 | 18 | |
19 | 19 | -- |
20 | --- База даних: `artbox_1` | |
20 | +-- База даних: `artbox_db` | |
21 | 21 | -- |
22 | 22 | |
23 | 23 | -- -------------------------------------------------------- |
... | ... | @@ -67,6 +67,7 @@ CREATE TABLE IF NOT EXISTS `image` ( |
67 | 67 | CREATE TABLE IF NOT EXISTS `language` ( |
68 | 68 | `language_id` int(2) NOT NULL AUTO_INCREMENT, |
69 | 69 | `lang_code` varchar(4) NOT NULL, |
70 | + `is_default` tinyint(1) NOT NULL, | |
70 | 71 | PRIMARY KEY (`language_id`) |
71 | 72 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ; |
72 | 73 | |
... | ... | @@ -74,9 +75,9 @@ CREATE TABLE IF NOT EXISTS `language` ( |
74 | 75 | -- Дамп даних таблиці `language` |
75 | 76 | -- |
76 | 77 | |
77 | -INSERT INTO `language` (`language_id`, `lang_code`) VALUES | |
78 | -(1, 'uk'), | |
79 | -(2, 'ru'); | |
78 | +INSERT INTO `language` (`language_id`, `lang_code`, `is_default`) VALUES | |
79 | +(1, 'uk', 1), | |
80 | +(2, 'ru', 0); | |
80 | 81 | |
81 | 82 | -- -------------------------------------------------------- |
82 | 83 | |
... | ... | @@ -245,7 +246,7 @@ CREATE TABLE IF NOT EXISTS `termin` ( |
245 | 246 | `termin_type_id` int(2) NOT NULL, |
246 | 247 | `page_id` int(6) NOT NULL DEFAULT '0', |
247 | 248 | PRIMARY KEY (`termin_id`) |
248 | -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=18 ; | |
249 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=19 ; | |
249 | 250 | |
250 | 251 | -- |
251 | 252 | -- Дамп даних таблиці `termin` |
... | ... | @@ -263,7 +264,8 @@ INSERT INTO `termin` (`termin_id`, `termin_type_id`, `page_id`) VALUES |
263 | 264 | (9, 0, 0), |
264 | 265 | (10, 0, 0), |
265 | 266 | (16, 0, 0), |
266 | -(17, 0, 0); | |
267 | +(17, 0, 0), | |
268 | +(18, 0, 0); | |
267 | 269 | |
268 | 270 | -- -------------------------------------------------------- |
269 | 271 | |
... | ... | @@ -294,7 +296,8 @@ INSERT INTO `termin_lang` (`termin_id`, `termin_title`, `lang_id`) VALUES |
294 | 296 | (9, 'Мотор (тип)', 1), |
295 | 297 | (10, 'Мотор (обьем)', 1), |
296 | 298 | (16, '1996', 1), |
297 | -(17, 'X5', 1); | |
299 | +(17, 'X5', 1), | |
300 | +(18, 'Новости', 0); | |
298 | 301 | |
299 | 302 | -- -------------------------------------------------------- |
300 | 303 | |
... | ... | @@ -305,6 +308,9 @@ INSERT INTO `termin_lang` (`termin_id`, `termin_title`, `lang_id`) VALUES |
305 | 308 | CREATE TABLE IF NOT EXISTS `termin_option` ( |
306 | 309 | `termin_id` int(6) NOT NULL, |
307 | 310 | `termin_pid` int(6) NOT NULL, |
311 | + `level` int(6) NOT NULL, | |
312 | + `lft` int(6) NOT NULL, | |
313 | + `rgt` int(6) NOT NULL, | |
308 | 314 | `sortorder` int(6) NOT NULL, |
309 | 315 | PRIMARY KEY (`termin_id`,`termin_pid`) |
310 | 316 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
... | ... | @@ -313,25 +319,26 @@ CREATE TABLE IF NOT EXISTS `termin_option` ( |
313 | 319 | -- Дамп даних таблиці `termin_option` |
314 | 320 | -- |
315 | 321 | |
316 | -INSERT INTO `termin_option` (`termin_id`, `termin_pid`, `sortorder`) VALUES | |
317 | -(1, 0, 1), | |
318 | -(2, 0, 2), | |
319 | -(3, 2, 1), | |
320 | -(4, 2, 2), | |
321 | -(5, 0, 3), | |
322 | -(6, 3, 1), | |
323 | -(6, 4, 1), | |
324 | -(7, 3, 2), | |
325 | -(7, 4, 2), | |
326 | -(8, 3, 3), | |
327 | -(8, 4, 3), | |
328 | -(9, 3, 4), | |
329 | -(9, 4, 4), | |
330 | -(10, 3, 5), | |
331 | -(10, 4, 5), | |
332 | -(16, 5, 4), | |
333 | -(17, 7, 0), | |
334 | -(17, 16, 0); | |
322 | +INSERT INTO `termin_option` (`termin_id`, `termin_pid`, `level`, `lft`, `rgt`, `sortorder`) VALUES | |
323 | +(1, 0, 0, 1, 2, 1), | |
324 | +(2, 0, 1, 3, 32, 2), | |
325 | +(3, 2, 2, 4, 17, 1), | |
326 | +(4, 2, 2, 18, 31, 2), | |
327 | +(5, 0, 1, 33, 38, 3), | |
328 | +(6, 3, 2, 19, 20, 1), | |
329 | +(6, 4, 2, 19, 20, 1), | |
330 | +(7, 3, 3, 21, 24, 2), | |
331 | +(7, 4, 3, 21, 24, 2), | |
332 | +(8, 3, 2, 25, 26, 3), | |
333 | +(8, 4, 2, 25, 26, 3), | |
334 | +(9, 3, 2, 27, 28, 4), | |
335 | +(9, 4, 2, 27, 28, 4), | |
336 | +(10, 3, 2, 29, 30, 5), | |
337 | +(10, 4, 2, 29, 30, 5), | |
338 | +(16, 5, 2, 34, 37, 4), | |
339 | +(17, 7, 2, 35, 36, 0), | |
340 | +(17, 16, 2, 35, 36, 0), | |
341 | +(18, 1, 0, 0, 0, 0); | |
335 | 342 | |
336 | 343 | -- -------------------------------------------------------- |
337 | 344 | ... | ... |
vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/left.php
... | ... | @@ -30,10 +30,9 @@ |
30 | 30 | [ |
31 | 31 | 'options' => ['class' => 'sidebar-menu'], |
32 | 32 | 'items' => [ |
33 | - ['label' => 'Page', 'icon' => 'fa fa-file-code-o', 'url' => ['/page/']], | |
34 | - ['label' => 'Termin', 'icon' => 'fa fa-file-code-o', 'url' => ['/termin/']], | |
35 | - ['label' => 'Termin Lang', 'icon' => 'fa fa-file-code-o', 'url' => ['/termin_lang/']], | |
36 | - ['label' => 'Menu', 'icon' => 'fa fa-file-code-o', 'url' => ['/menu/']], | |
33 | + ['label' => 'Страница', 'icon' => 'fa fa-file-code-o', 'url' => ['/page/']], | |
34 | + ['label' => 'Термин', 'icon' => 'fa fa-file-code-o', 'url' => ['/termin_lang/']], | |
35 | + ['label' => 'Меню', 'icon' => 'fa fa-file-code-o', 'url' => ['/menu/']], | |
37 | 36 | ['label' => 'Gii', 'icon' => 'fa fa-file-code-o', 'url' => ['/gii']], |
38 | 37 | ['label' => 'Debug', 'icon' => 'fa fa-dashboard', 'url' => ['/debug']], |
39 | 38 | ['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest], | ... | ... |
vendor/yiisoft/yii2/base/Application.php
... | ... | @@ -109,6 +109,12 @@ abstract class Application extends Module |
109 | 109 | * @see sourceLanguage |
110 | 110 | */ |
111 | 111 | public $language = 'en-US'; |
112 | + | |
113 | + /** | |
114 | + * @var int - текущий язык | |
115 | + */ | |
116 | + public $lang_id = 1; | |
117 | + | |
112 | 118 | /** |
113 | 119 | * @var string the language that the application is written in. This mainly refers to |
114 | 120 | * the language that the messages and view files are written in. | ... | ... |