1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: office-pb1 |
5
|
|
|
* Date: 18.07.14 |
6
|
|
|
* Time: 20:49 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Page\Controller; |
10
|
|
|
|
11
|
|
|
use Application\Mvc\Controller; |
12
|
|
|
use Page\Model\Page; |
13
|
|
|
use Page\Form\PageForm; |
14
|
|
|
|
15
|
|
|
class AdminController extends Controller |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
public function initialize() |
19
|
|
|
{ |
20
|
|
|
$this->setAdminEnvironment(); |
21
|
|
|
$this->helper->activeMenu()->setActive('admin-page'); |
22
|
|
|
Page::setTranslateCache(false); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function indexAction() |
26
|
|
|
{ |
27
|
|
|
$this->view->entries = Page::find(); |
|
|
|
|
28
|
|
|
|
29
|
|
|
$this->helper->title($this->helper->at('Manage Pages'), true); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
View Code Duplication |
public function addAction() |
33
|
|
|
{ |
34
|
|
|
$this->view->pick(['admin/edit']); |
35
|
|
|
$form = new PageForm(); |
36
|
|
|
$model = new Page(); |
37
|
|
|
|
38
|
|
|
if ($this->request->isPost()) { |
39
|
|
|
$post = $this->request->getPost(); |
40
|
|
|
$form->bind($post, $model); |
41
|
|
|
if ($form->isValid()) { |
42
|
|
|
if ($model->create()) { |
43
|
|
|
$form->bind($post, $model); |
44
|
|
|
$model->updateFields($post); |
45
|
|
|
if ($model->update()) { |
46
|
|
|
$this->flash->success($this->helper->at('Page created')); |
47
|
|
|
return $this->redirect($this->url->get() . 'page/admin/edit/' . $model->getId() . '?lang=' . LANG); |
48
|
|
|
} else { |
49
|
|
|
$this->flashErrors($model); |
50
|
|
|
} |
51
|
|
|
} else { |
52
|
|
|
$this->flashErrors($model); |
53
|
|
|
} |
54
|
|
|
} else { |
55
|
|
|
$this->flashErrors($form); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$this->helper->title($this->helper->at('Manage Pages'), true); |
60
|
|
|
|
61
|
|
|
$this->view->model = $model; |
|
|
|
|
62
|
|
|
$this->view->form = $form; |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function editAction($id) |
66
|
|
|
{ |
67
|
|
|
$id = (int) $id; |
68
|
|
|
$form = new PageForm(); |
69
|
|
|
$model = Page::findFirst($id); |
|
|
|
|
70
|
|
|
|
71
|
|
|
if ($model->getSlug() == 'index') { |
|
|
|
|
72
|
|
|
$form->get('slug')->setAttribute('disabled', 'disabled'); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
if ($this->request->isPost()) { |
76
|
|
|
$post = $this->request->getPost(); |
77
|
|
|
$form->bind($post, $model); |
78
|
|
|
if ($form->isValid()) { |
79
|
|
|
$model->updateFields($post); |
|
|
|
|
80
|
|
|
if ($model->save()) { |
|
|
|
|
81
|
|
|
$this->flash->success($this->helper->at('Updated has been successful')); |
82
|
|
|
|
83
|
|
|
// Очищаем кеш страницы |
84
|
|
|
$query = "slug = '{$model->getSlug()}'"; |
|
|
|
|
85
|
|
|
$key = md5("Page::findFirst($query)"); |
86
|
|
|
$this->cache->delete($key); |
87
|
|
|
|
88
|
|
|
return $this->redirect($this->url->get() . 'page/admin/edit/' . $model->getId() . '?lang=' . LANG); |
|
|
|
|
89
|
|
|
} else { |
90
|
|
|
$this->flashErrors($model); |
91
|
|
|
} |
92
|
|
|
} else { |
93
|
|
|
$this->flashErrors($form); |
94
|
|
|
} |
95
|
|
|
} else { |
96
|
|
|
$form->setEntity($model); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$this->view->model = $model; |
|
|
|
|
100
|
|
|
$this->view->form = $form; |
|
|
|
|
101
|
|
|
$this->helper->title($this->helper->at('Edit Page'), true); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function deleteAction($id) |
105
|
|
|
{ |
106
|
|
|
$model = Page::findFirst($id); |
|
|
|
|
107
|
|
|
|
108
|
|
|
if ($model->getSlug() == 'index') { |
|
|
|
|
109
|
|
|
$this->flash->error($this->helper->at('Index page can not be removed')); |
110
|
|
|
return $this->redirect($this->url->get() . 'page/admin'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if ($this->request->isPost()) { |
114
|
|
|
$model->delete(); |
|
|
|
|
115
|
|
|
$this->redirect($this->url->get() . 'page/admin'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$this->view->model = $model; |
|
|
|
|
119
|
|
|
$this->helper->title($this->helper->at('Delete Page'), true); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
} |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: