1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\backend\controllers; |
4
|
|
|
|
5
|
|
|
use app\models\Route; |
6
|
|
|
use app\properties\url\FullCategoryPathPart; |
7
|
|
|
use app\properties\url\ObjectSlugPart; |
8
|
|
|
use app\properties\url\PartialCategoryPathPart; |
9
|
|
|
use app\properties\url\PropertyPart; |
10
|
|
|
use app\properties\url\StaticPart; |
11
|
|
|
use Yii; |
12
|
|
|
use yii\filters\AccessControl; |
13
|
|
|
use yii\helpers\Url; |
14
|
|
|
use yii\web\Controller; |
15
|
|
|
|
16
|
|
|
class RouteController extends Controller |
17
|
|
|
{ |
18
|
|
View Code Duplication |
public function behaviors() |
19
|
|
|
{ |
20
|
|
|
return [ |
21
|
|
|
'access' => [ |
22
|
|
|
'class' => AccessControl::className(), |
|
|
|
|
23
|
|
|
'rules' => [ |
24
|
|
|
[ |
25
|
|
|
'allow' => true, |
26
|
|
|
'roles' => ['setting manage'], |
27
|
|
|
], |
28
|
|
|
], |
29
|
|
|
], |
30
|
|
|
]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
View Code Duplication |
public function actionIndex() |
34
|
|
|
{ |
35
|
|
|
$searchModel = new Route(); |
36
|
|
|
$dataProvider = $searchModel->search($_GET); |
37
|
|
|
|
38
|
|
|
return $this->render( |
39
|
|
|
'index', |
40
|
|
|
[ |
41
|
|
|
'dataProvider' => $dataProvider, |
42
|
|
|
'searchModel' => $searchModel, |
43
|
|
|
] |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function actionEdit($id = null) |
48
|
|
|
{ |
49
|
|
|
$model = new Route; |
50
|
|
|
if ($id !== null) { |
51
|
|
|
$model = Route::findOne($id); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
if ($model->load(\Yii::$app->request->post()) && $model->validate()) { |
56
|
|
|
$save_result = $model->save(); |
57
|
|
View Code Duplication |
if ($save_result) { |
58
|
|
|
Yii::$app->session->setFlash('success', Yii::t('app', 'Record has been saved')); |
59
|
|
|
$this->redirect(Url::toRoute(['/backend/route/edit', 'id'=>$model->id])); |
60
|
|
|
} else { |
61
|
|
|
Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot save data')); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$settings_by_class = []; |
66
|
|
|
$temporary_objects = [ |
67
|
|
|
new StaticPart(), |
68
|
|
|
new PropertyPart(), |
69
|
|
|
new PartialCategoryPathPart(), |
70
|
|
|
new ObjectSlugPart(), |
71
|
|
|
new FullCategoryPathPart(), |
72
|
|
|
|
73
|
|
|
]; |
74
|
|
|
foreach ($temporary_objects as $obj) { |
75
|
|
|
$vars = get_object_vars($obj); |
76
|
|
|
$vars_by_type = []; |
77
|
|
|
foreach ($vars as $key => $value) { |
78
|
|
|
if (in_array($key, ['object', 'model', 'rest_part', 'gathered_part'])) { |
79
|
|
|
continue; |
80
|
|
|
} |
81
|
|
|
if ($key != 'parameters') { |
82
|
|
|
$vars_by_type[$key] = gettype($value); |
83
|
|
|
} else { |
84
|
|
|
$vars_by_type[$key]=[]; |
85
|
|
|
foreach ($value as $param_key => $param_value) { |
86
|
|
|
$vars_by_type[$key][$param_key] = gettype($param_value); |
87
|
|
|
if ($vars_by_type[$key][$param_key] == 'NULL') { |
88
|
|
|
$vars_by_type[$key][$param_key] = 'string'; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
$settings_by_class[get_class($obj)] = $vars_by_type; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $this->render( |
97
|
|
|
'edit', |
98
|
|
|
[ |
99
|
|
|
'model' => $model, |
100
|
|
|
'settings_by_class' => $settings_by_class, |
101
|
|
|
] |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.