1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\modules\admin\controllers; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use yii\filters\VerbFilter; |
7
|
|
|
use yii\helpers\Url; |
8
|
|
|
use app\components\BaseController; |
9
|
|
|
use app\models\Region; |
10
|
|
|
use app\modules\admin\models\search\RegionSearch; |
11
|
|
|
|
12
|
|
|
class RegionsController extends BaseController |
13
|
|
|
{ |
14
|
|
|
public function behaviors() |
15
|
|
|
{ |
16
|
|
|
return [ |
17
|
|
|
'verbs' => [ |
18
|
|
|
'class' => VerbFilter::className(), |
19
|
|
|
'actions' => [ |
20
|
|
|
'delete' => ['post'], |
21
|
|
|
'operations' => ['post'], |
22
|
|
|
'autocomplete' => ['post'], |
23
|
|
|
], |
24
|
|
|
], |
25
|
|
|
]; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function actions() |
29
|
|
|
{ |
30
|
|
|
return [ |
31
|
|
|
'operations' => [ |
32
|
|
|
'class' => 'app\modules\admin\controllers\common\OperationsAction', |
33
|
|
|
'modelName' => 'app\models\Region', |
34
|
|
|
'operations' => [ |
35
|
|
|
'delete' => [], |
36
|
|
|
] |
37
|
|
|
], |
38
|
|
|
'delete' => [ |
39
|
|
|
'class' => 'app\modules\admin\controllers\common\DeleteAction', |
40
|
|
|
'modelName' => 'app\models\Region', |
41
|
|
|
], |
42
|
|
|
]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function actionIndex() |
46
|
|
|
{ |
47
|
|
|
$regionSearch = new RegionSearch(); |
48
|
|
|
$dataProvider = $regionSearch->search(Yii::$app->request->get()); |
49
|
|
|
|
50
|
|
|
return $this->render('index', [ |
51
|
|
|
'regionSearch' => $regionSearch, |
52
|
|
|
'dataProvider' => $dataProvider, |
53
|
|
|
]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function actionEdit($id = null) |
57
|
|
|
{ |
58
|
|
|
$model = new Region(); |
59
|
|
|
|
60
|
|
|
if ($id) { |
61
|
|
|
$model = $this->loadModel($model, $id); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if (Yii::$app->request->isPost) { |
65
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
66
|
|
|
Yii::$app->session->setFlash('success', Yii::t('app', 'Saved successfully')); |
67
|
|
|
if (Yii::$app->request->isAjax) { |
68
|
|
|
return $this->response(['redirect' => Url::toRoute(['edit', 'id' => $model->region_id])]); |
69
|
|
|
} |
70
|
|
|
} else { |
71
|
|
|
if (Yii::$app->request->isAjax) { |
72
|
|
|
return $this->response(\app\helpers\Util::getValidationErrors($model)); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $this->render('edit', ['model' => $model]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function actionAutocomplete() |
81
|
|
|
{ |
82
|
|
|
$result = []; |
83
|
|
|
if (($term = Yii::$app->request->post('term')) !== null) { |
84
|
|
|
$data = Region::find() |
85
|
|
|
->joinWith('country') |
86
|
|
|
->like($term, 'region.title') |
87
|
|
|
->asArray() |
88
|
|
|
->limit(10) |
89
|
|
|
->all(); |
90
|
|
|
|
91
|
|
|
foreach ($data as $item) { |
92
|
|
|
$result[] = [ |
93
|
|
|
'text' => $item['title'], |
94
|
|
|
'id' => $item['region_id'] |
95
|
|
|
]; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
return $this->response($result); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.