1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\controllers; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use app\models\TemplateBackground; |
7
|
|
|
use app\models\TemplateBackgroundUpload; |
8
|
|
|
use yii\data\ActiveDataProvider; |
9
|
|
|
use yii\web\Controller; |
10
|
|
|
use yii\web\NotFoundHttpException; |
11
|
|
|
use yii\web\UploadedFile; |
12
|
|
|
use yii\filters\VerbFilter; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* TemplateBackgroundController implements the CRUD actions for TemplateBackground model. |
16
|
|
|
*/ |
17
|
|
|
class TemplateBackgroundController extends Controller |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
public function behaviors() |
23
|
|
|
{ |
24
|
|
|
return [ |
25
|
|
|
'verbs' => [ |
26
|
|
|
'class' => VerbFilter::class, |
27
|
|
|
'actions' => [ |
28
|
|
|
'delete' => ['POST'], |
29
|
|
|
], |
30
|
|
|
], |
31
|
|
|
]; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Lists all TemplateBackground models. |
36
|
|
|
* |
37
|
|
|
* @return string render |
38
|
|
|
*/ |
39
|
|
|
public function actionIndex() |
40
|
|
|
{ |
41
|
|
|
$dataProvider = new ActiveDataProvider([ |
42
|
|
|
'query' => TemplateBackground::find(), |
43
|
|
|
]); |
44
|
|
|
|
45
|
|
|
if (Yii::$app->request->isAjax) { |
46
|
|
|
return $this->renderAjax('index', [ |
47
|
|
|
'dataProvider' => $dataProvider, |
48
|
|
|
]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $this->render('index', [ |
52
|
|
|
'dataProvider' => $dataProvider, |
53
|
|
|
]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Creates a new TemplateBackground model. |
58
|
|
|
* If creation is successful, the browser will be redirected to the 'view' page. |
59
|
|
|
* |
60
|
|
|
* @return \yii\web\Response|string redirect or render |
61
|
|
|
*/ |
62
|
|
|
public function actionCreate() |
63
|
|
|
{ |
64
|
|
|
$modelUpload = new TemplateBackgroundUpload(); |
65
|
|
|
if ($modelUpload->load(Yii::$app->request->post()) && $modelUpload->upload(UploadedFile::getInstance($modelUpload, 'background'))) { |
66
|
|
|
if (Yii::$app->request->isAjax) { |
67
|
|
|
return ''; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $this->redirect(['index']); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if (Yii::$app->request->isAjax) { |
74
|
|
|
return $this->renderAjax('create', [ |
75
|
|
|
'model' => $modelUpload, |
76
|
|
|
]); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $this->render('create', [ |
80
|
|
|
'model' => $modelUpload, |
81
|
|
|
]); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Deletes an existing TemplateBackground model. |
86
|
|
|
* If deletion is successful, the browser will be redirected to the 'index' page. |
87
|
|
|
* |
88
|
|
|
* @param int $id |
89
|
|
|
* |
90
|
|
|
* @return \yii\web\Response|string |
91
|
|
|
*/ |
92
|
|
|
public function actionDelete($id) |
93
|
|
|
{ |
94
|
|
|
$this->findModel($id)->delete(); |
95
|
|
|
|
96
|
|
|
if (Yii::$app->request->isAjax) { |
97
|
|
|
return ''; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $this->redirect(['index']); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Finds the TemplateBackground model based on its primary key value. |
105
|
|
|
* If the model is not found, a 404 HTTP exception will be thrown. |
106
|
|
|
* |
107
|
|
|
* @param int $id |
108
|
|
|
* |
109
|
|
|
* @return TemplateBackground the loaded model |
110
|
|
|
* |
111
|
|
|
* @throws NotFoundHttpException if the model cannot be found |
112
|
|
|
*/ |
113
|
|
View Code Duplication |
protected function findModel($id) |
114
|
|
|
{ |
115
|
|
|
if (($model = TemplateBackground::findOne($id)) !== null) { |
|
|
|
|
116
|
|
|
return $model; |
117
|
|
|
} else { |
118
|
|
|
throw new NotFoundHttpException(Yii::t('app', 'The requested template background does not exist.')); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|