Commit 6fc556857c7a6cc241459d731651661efaa6d011
1 parent
6465b905
add logo in admin
Showing
4 changed files
with
218 additions
and
0 deletions
Show diff stats
1 | +<?php | |
2 | + /** | |
3 | + * Created by PhpStorm. | |
4 | + * User: stes | |
5 | + * Date: 12.09.18 | |
6 | + * Time: 16:39 | |
7 | + */ | |
8 | + | |
9 | + namespace backend\controllers; | |
10 | + | |
11 | + use artbox\core\admin\actions\Delete; | |
12 | + use artbox\core\admin\actions\Index; | |
13 | + use artbox\core\admin\actions\View; | |
14 | + use artbox\core\admin\interfaces\ControllerInterface; | |
15 | + use backend\actions\Create; | |
16 | + use backend\actions\Update; | |
17 | + use backend\widgets\Form; | |
18 | + use common\models\Logo; | |
19 | + use yii\filters\AccessControl; | |
20 | + use yii\filters\VerbFilter; | |
21 | + use yii\web\Controller; | |
22 | + use yii\web\NotFoundHttpException; | |
23 | + | |
24 | + class LogoController extends Controller implements ControllerInterface | |
25 | + { | |
26 | + public function behaviors() | |
27 | + { | |
28 | + return [ | |
29 | + 'verbs' => [ | |
30 | + 'class' => VerbFilter::className(), | |
31 | + 'actions' => [ | |
32 | + 'delete' => [ 'POST' ], | |
33 | + ], | |
34 | + ], | |
35 | + 'access' => [ | |
36 | + 'class' => AccessControl::className(), | |
37 | + 'rules' => [ | |
38 | + [ | |
39 | + 'allow' => true, | |
40 | + 'roles' => [ '@' ], | |
41 | + ], | |
42 | + ], | |
43 | + ], | |
44 | + ]; | |
45 | + } | |
46 | + public function actions() | |
47 | + { | |
48 | + return [ | |
49 | + 'index' => [ | |
50 | + 'class' => Index::className(), | |
51 | + 'columns' => [ | |
52 | + 'link' => [ | |
53 | + 'type' => Index::ACTION_COL, | |
54 | + ], | |
55 | + 'sort' => [ | |
56 | + 'type' => Index::POSITION_COL, | |
57 | + ], | |
58 | + ], | |
59 | + 'model' => Logo::className(), | |
60 | + 'hasLanguage' => false, | |
61 | + 'enableMassDelete' => true, | |
62 | + 'modelPrimaryKey' => 'id', | |
63 | + ], | |
64 | + 'create' => array_merge([ 'class' => Create::className() ], self::fieldsConfig()), | |
65 | + 'update' => array_merge([ 'class' => Update::className() ], self::fieldsConfig()), | |
66 | + 'view' => [ | |
67 | + 'class' => View::className(), | |
68 | + 'model' => Logo::className(), | |
69 | + 'hasAlias' => true, | |
70 | + 'hasGallery' => true, | |
71 | + 'fields' => [ | |
72 | + [ | |
73 | + 'name' => 'image_id', | |
74 | + 'type' => Form::IMAGE, | |
75 | + ], | |
76 | + ], | |
77 | + ], | |
78 | + 'delete' => [ | |
79 | + 'class' => Delete::className(), | |
80 | + ], | |
81 | + ]; | |
82 | + } | |
83 | + | |
84 | + public function findModel($id) | |
85 | + { | |
86 | + $model = Logo::find() | |
87 | + ->where([ 'id' => $id ]) | |
88 | + ->one(); | |
89 | + if ($model !== null) { | |
90 | + return $model; | |
91 | + } else { | |
92 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
93 | + } | |
94 | + } | |
95 | + | |
96 | + public function newModel() | |
97 | + { | |
98 | + return new Logo(); | |
99 | + } | |
100 | + | |
101 | + public function deleteModel($id) | |
102 | + { | |
103 | + $page = Logo::find() | |
104 | + ->where( | |
105 | + [ | |
106 | + 'id' => $id, | |
107 | + ] | |
108 | + ) | |
109 | + ->one(); | |
110 | + | |
111 | + return $page->delete(); | |
112 | + } | |
113 | + | |
114 | + protected static function fieldsConfig() | |
115 | + { | |
116 | + return [ | |
117 | + 'model' => Logo::className(), | |
118 | + 'hasAlias' => false, | |
119 | + 'hasGallery' => false, | |
120 | + 'languageFields' => [ | |
121 | + ], | |
122 | + 'fields' => [ | |
123 | + | |
124 | + [ | |
125 | + 'name' => 'image_id', | |
126 | + 'type' => Form::IMAGE, | |
127 | + ], | |
128 | + [ | |
129 | + 'name' => 'sort', | |
130 | + 'type' => Form::NUMBER, | |
131 | + ], | |
132 | + ], | |
133 | + ]; | |
134 | + } | |
135 | + } | |
0 | 136 | \ No newline at end of file | ... | ... |
backend/views/layouts/menu_items.php
1 | +<?php | |
2 | + | |
3 | +namespace common\models; | |
4 | + | |
5 | +use Yii; | |
6 | + | |
7 | +/** | |
8 | + * This is the model class for table "logo". | |
9 | + * | |
10 | + * @property int $id | |
11 | + * @property int $image_id | |
12 | + * @property string $link | |
13 | + * @property int $sort | |
14 | + */ | |
15 | +class Logo extends \yii\db\ActiveRecord | |
16 | +{ | |
17 | + /** | |
18 | + * {@inheritdoc} | |
19 | + */ | |
20 | + public static function tableName() | |
21 | + { | |
22 | + return 'logo'; | |
23 | + } | |
24 | + | |
25 | + /** | |
26 | + * {@inheritdoc} | |
27 | + */ | |
28 | + public function rules() | |
29 | + { | |
30 | + return [ | |
31 | + [['image_id', 'sort'], 'default', 'value' => null], | |
32 | + [['image_id', 'sort'], 'integer'], | |
33 | + [['link'], 'string'], | |
34 | + ]; | |
35 | + } | |
36 | + | |
37 | + /** | |
38 | + * {@inheritdoc} | |
39 | + */ | |
40 | + public function attributeLabels() | |
41 | + { | |
42 | + return [ | |
43 | + 'id' => Yii::t('app', 'ID'), | |
44 | + 'image_id' => Yii::t('app', 'Image ID'), | |
45 | + 'link' => Yii::t('app', 'Link'), | |
46 | + 'sort' => Yii::t('app', 'Sort'), | |
47 | + ]; | |
48 | + } | |
49 | +} | ... | ... |
console/migrations/m180912_134138_create_logo_table.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +use yii\db\Migration; | |
4 | + | |
5 | +/** | |
6 | + * Handles the creation of table `logo`. | |
7 | + */ | |
8 | +class m180912_134138_create_logo_table extends Migration | |
9 | +{ | |
10 | + /** | |
11 | + * {@inheritdoc} | |
12 | + */ | |
13 | + public function safeUp() | |
14 | + { | |
15 | + $this->createTable('logo', [ | |
16 | + 'id' => $this->primaryKey(), | |
17 | + 'image_id' => $this->integer(), | |
18 | + 'link' => $this->text(), | |
19 | + 'sort' => $this->integer() | |
20 | + ]); | |
21 | + } | |
22 | + | |
23 | + /** | |
24 | + * {@inheritdoc} | |
25 | + */ | |
26 | + public function safeDown() | |
27 | + { | |
28 | + $this->dropTable('logo'); | |
29 | + } | |
30 | +} | ... | ... |