Commit 7f4032232a67fbb5060166e9112104aeb24f3fae
1 parent
8bc87953
- add image to services
Showing
3 changed files
with
51 additions
and
2 deletions
Show diff stats
backend/controllers/ServiceController.php
@@ -165,7 +165,10 @@ | @@ -165,7 +165,10 @@ | ||
165 | ], | 165 | ], |
166 | ], | 166 | ], |
167 | 'fields' => [ | 167 | 'fields' => [ |
168 | - | 168 | + [ |
169 | + 'name' => 'image_id', | ||
170 | + 'type' => Form::IMAGE | ||
171 | + ], | ||
169 | [ | 172 | [ |
170 | 'name' => 'parent_id', | 173 | 'name' => 'parent_id', |
171 | 'type' => Form::RELATION, | 174 | 'type' => Form::RELATION, |
common/models/Service.php
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | 2 | ||
3 | namespace common\models; | 3 | namespace common\models; |
4 | 4 | ||
5 | +use artbox\core\models\Image; | ||
5 | use artbox\core\models\traits\AliasableTrait; | 6 | use artbox\core\models\traits\AliasableTrait; |
6 | use backend\behaviors\LevelBehavior; | 7 | use backend\behaviors\LevelBehavior; |
7 | use Yii; | 8 | use Yii; |
@@ -82,7 +83,7 @@ class Service extends ActiveRecord | @@ -82,7 +83,7 @@ class Service extends ActiveRecord | ||
82 | { | 83 | { |
83 | return [ | 84 | return [ |
84 | [['parent_id', 'sort', 'level', 'created_at', 'updated_at'], 'default', 'value' => null], | 85 | [['parent_id', 'sort', 'level', 'created_at', 'updated_at'], 'default', 'value' => null], |
85 | - [['sort', 'level', 'created_at', 'updated_at'], 'integer'], | 86 | + [['sort', 'level', 'created_at', 'updated_at', 'image_id'], 'integer'], |
86 | [['status'], 'boolean'], | 87 | [['status'], 'boolean'], |
87 | ]; | 88 | ]; |
88 | } | 89 | } |
@@ -100,6 +101,7 @@ class Service extends ActiveRecord | @@ -100,6 +101,7 @@ class Service extends ActiveRecord | ||
100 | 'level' => Yii::t('app', 'Level'), | 101 | 'level' => Yii::t('app', 'Level'), |
101 | 'created_at' => Yii::t('app', 'Created At'), | 102 | 'created_at' => Yii::t('app', 'Created At'), |
102 | 'updated_at' => Yii::t('app', 'Updated At'), | 103 | 'updated_at' => Yii::t('app', 'Updated At'), |
104 | + 'image_id' => Yii::t('app', 'Image'), | ||
103 | ]; | 105 | ]; |
104 | } | 106 | } |
105 | 107 | ||
@@ -135,4 +137,8 @@ class Service extends ActiveRecord | @@ -135,4 +137,8 @@ class Service extends ActiveRecord | ||
135 | ] | 137 | ] |
136 | ); | 138 | ); |
137 | } | 139 | } |
140 | + | ||
141 | + public function getImage(){ | ||
142 | + return $this->hasOne(Image::className(), ['id' => 'image_id']); | ||
143 | + } | ||
138 | } | 144 | } |
console/migrations/m180523_112936_alter_table_service.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +/** | ||
6 | + * Class m180523_112936_alter_table_service | ||
7 | + */ | ||
8 | +class m180523_112936_alter_table_service extends Migration | ||
9 | +{ | ||
10 | + /** | ||
11 | + * {@inheritdoc} | ||
12 | + */ | ||
13 | + public function safeUp() | ||
14 | + { | ||
15 | + $this->addColumn('service', 'image_id', $this->integer()); | ||
16 | + } | ||
17 | + | ||
18 | + /** | ||
19 | + * {@inheritdoc} | ||
20 | + */ | ||
21 | + public function safeDown() | ||
22 | + { | ||
23 | + $this->dropColumn('service', 'image_id'); | ||
24 | + } | ||
25 | + | ||
26 | + /* | ||
27 | + // Use up()/down() to run migration code without a transaction. | ||
28 | + public function up() | ||
29 | + { | ||
30 | + | ||
31 | + } | ||
32 | + | ||
33 | + public function down() | ||
34 | + { | ||
35 | + echo "m180523_112936_alter_table_service cannot be reverted.\n"; | ||
36 | + | ||
37 | + return false; | ||
38 | + } | ||
39 | + */ | ||
40 | +} |