1
|
|
|
<?php |
2
|
|
|
namespace app\controllers; |
3
|
|
|
|
4
|
|
|
class Examples extends \erdiko\controllers\Web |
5
|
|
|
{ |
6
|
|
|
use \erdiko\theme\traits\Controller; // Add theme engine suport (for convenience) |
7
|
|
|
|
8
|
|
View Code Duplication |
public function get($request, $response, $args) |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
// $this->container->logger->debug("examples"); |
|
|
|
|
11
|
|
|
$view = 'examples/list.html'; |
12
|
|
|
|
13
|
|
|
// Get erdiko config, this gets application.json and loads the theme specified |
14
|
|
|
// $themeData = \erdiko\theme\Config::get(); |
|
|
|
|
15
|
|
|
$themeData['theme'] = \erdiko\theme\Config::get($this->container->get('settings')['theme']); |
|
|
|
|
16
|
|
|
// $themeData['args'] = $args; // optional |
|
|
|
|
17
|
|
|
|
18
|
|
|
$themeData['page'] = [ |
19
|
|
|
'title' => "Erdiko Web Example", |
20
|
|
|
'hello' => "world" |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
return $this->container->theme->render($response, $view, $themeData); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
View Code Duplication |
public function getOnecolumn($request, $response, $args) |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$this->container->logger->debug("route: /config"); |
29
|
|
|
$view = 'layouts/1column.html'; |
30
|
|
|
$themeData['theme'] = \erdiko\theme\Config::get($this->container->get('settings')['theme']); |
|
|
|
|
31
|
|
|
$themeData['page']['title'] = "1 Column Layout"; |
32
|
|
|
|
33
|
|
|
return $this->container->theme->render($response, $view, $themeData); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
View Code Duplication |
public function getTwocolumn($request, $response, $args) |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$this->container->logger->debug("route: /config"); |
39
|
|
|
$view = 'layouts/2column.html'; |
40
|
|
|
$themeData['theme'] = \erdiko\theme\Config::get($this->container->get('settings')['theme']); |
|
|
|
|
41
|
|
|
$themeData['page']['title'] = "2 Column Layout"; |
42
|
|
|
|
43
|
|
|
return $this->container->theme->render($response, $view, $themeData); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
View Code Duplication |
public function getThreecolumn($request, $response, $args) |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
$this->container->logger->debug("route: /config"); |
49
|
|
|
$view = 'layouts/3column.html'; |
50
|
|
|
$themeData['theme'] = \erdiko\theme\Config::get($this->container->get('settings')['theme']); |
|
|
|
|
51
|
|
|
$themeData['page']['title'] = "3 Column Layout"; |
52
|
|
|
|
53
|
|
|
return $this->container->theme->render($response, $view, $themeData); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
View Code Duplication |
public function getJohn($request, $response, $args) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$view = 'pages/example.html'; |
59
|
|
|
|
60
|
|
|
// Get erdiko config, this gets application.json and loads the theme specified |
61
|
|
|
$themeData['theme'] = \erdiko\theme\Config::get($this->container->get('settings')['theme']); |
|
|
|
|
62
|
|
|
$themeData['args'] = $args; // optional |
63
|
|
|
$themeData['page'] = [ |
64
|
|
|
'title' => "Erdiko Web Example" |
65
|
|
|
]; |
66
|
|
|
|
67
|
|
|
return $this->container->theme->render($response, $view, $themeData); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
View Code Duplication |
public function getMarkup($request, $response, $args) |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$view = 'examples/markup.html'; |
73
|
|
|
|
74
|
|
|
// Get erdiko config, this gets application.json and loads the theme specified |
75
|
|
|
$themeData['theme'] = \erdiko\theme\Config::get($this->container->get('settings')['theme']); |
|
|
|
|
76
|
|
|
$themeData['args'] = $args; // optional |
77
|
|
|
$themeData['page'] = [ |
78
|
|
|
'title' => "Markup Example" |
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
return $this->container->theme->render($response, $view, $themeData); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
View Code Duplication |
public function getCarousel($request, $response, $args) |
|
|
|
|
85
|
|
|
{ |
86
|
|
|
$view = 'examples/carousel.html'; |
87
|
|
|
|
88
|
|
|
// Get erdiko config, this gets application.json and loads the theme specified |
89
|
|
|
$themeData['theme'] = \erdiko\theme\Config::get($this->container->get('settings')['theme']); |
|
|
|
|
90
|
|
|
$themeData['page'] = [ |
91
|
|
|
'title' => "Fullpage Example", |
92
|
|
|
'description' => "This is the description of the page." |
93
|
|
|
]; |
94
|
|
|
|
95
|
|
|
return $this->container->theme->render($response, $view, $themeData); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Leverage the theme trait to easily add content to an action |
100
|
|
|
*/ |
101
|
|
|
public function getTheme($request, $response, $args) |
102
|
|
|
{ |
103
|
|
|
$this->getThemeEngine(); |
104
|
|
|
$this->theme->title = "Theme Engine Example"; |
105
|
|
|
$this->theme->description = "This page is rendered using the erdiko theme engine. |
106
|
|
|
\\erdiko\\theme\\Engine"; |
107
|
|
|
|
108
|
|
|
return $this->render($response, null, $theme); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Alternative way to use the theme Engine (explicit) |
113
|
|
|
* In this approach it does not rely on the theme trait |
114
|
|
|
*/ |
115
|
|
|
public function getTheme2($request, $response, $args) |
116
|
|
|
{ |
117
|
|
|
$theme = new \erdiko\theme\Engine( $this->container->get('settings')['theme'] ); |
|
|
|
|
118
|
|
|
$theme->title = "Theme Engine Example"; |
119
|
|
|
$theme->description = "This page is rendered with the erdiko theme engine. |
120
|
|
|
It does not leverage the erdiko theme trait. |
121
|
|
|
\\erdiko\\theme\\Engine"; |
122
|
|
|
|
123
|
|
|
return $this->container->theme->render($response, $theme->getDefaultView(), $theme->toArray()); |
124
|
|
|
// return $this->render($response, null, $theme); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function getFlash($request, $response, $args) |
128
|
|
|
{ |
129
|
|
|
$view = 'page.html'; |
130
|
|
|
|
131
|
|
|
// Add some flash messages |
132
|
|
|
$this->container->flash->addMessage('success', 'This is a success message'); |
133
|
|
|
$this->container->flash->addMessage('info', 'This is an info message'); |
134
|
|
|
$this->container->flash->addMessage('warning', 'This is a warning message'); |
135
|
|
|
$this->container->flash->addMessage('danger', 'This is a danger (error) message'); |
136
|
|
|
|
137
|
|
|
// Get erdiko config, this gets application.json and loads the theme specified |
138
|
|
|
$themeData['theme'] = \erdiko\theme\Config::get($this->container->get('settings')['theme']); |
|
|
|
|
139
|
|
|
$themeData['args'] = $args; |
140
|
|
|
$themeData['page'] = [ |
141
|
|
|
'title' => "Flash Message Example" |
142
|
|
|
]; |
143
|
|
|
|
144
|
|
|
return $this->container->theme->render($response, $view, $themeData); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function getGrid($request, $response, $args) |
148
|
|
|
{ |
149
|
|
|
$this->container->logger->debug("/controller"); |
150
|
|
|
$view = 'examples/grid.html'; |
151
|
|
|
|
152
|
|
|
// Get erdiko config, this gets application.json and loads the theme specified |
153
|
|
|
$themeData['theme'] = \erdiko\theme\Config::get($this->container->get('settings')['theme']); |
|
|
|
|
154
|
|
|
// $this->container->logger->debug("config: ".print_r($config, true)); |
|
|
|
|
155
|
|
|
|
156
|
|
|
// Generate data for grid |
157
|
|
|
$item = [ |
158
|
|
|
'url' => "#", |
159
|
|
|
'image' => "/images/grid-item.png", |
160
|
|
|
'name' => "Item" |
161
|
|
|
]; |
162
|
|
|
$items = array(); |
163
|
|
|
$max = (int)$args['param']; |
164
|
|
|
$this->container->logger->debug("param: ".$max); |
165
|
|
|
|
166
|
|
View Code Duplication |
for($i = 0; $i < $max; $i++) { |
|
|
|
|
167
|
|
|
$item['name'] = "Item $i"; |
168
|
|
|
$items[] = $item; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
$themeData['page'] = [ |
172
|
|
|
'title' => "Grid Example", |
173
|
|
|
'items' => $items |
174
|
|
|
]; |
175
|
|
|
|
176
|
|
|
return $this->container->theme->render($response, $view, $themeData); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
View Code Duplication |
public function getFullpage($request, $response, $args) |
|
|
|
|
180
|
|
|
{ |
181
|
|
|
$view = 'fullpage.html'; |
182
|
|
|
|
183
|
|
|
// Get erdiko config, this gets application.json and loads the theme specified |
184
|
|
|
$themeData['theme'] = \erdiko\theme\Config::get($this->container->get('settings')['theme']); |
|
|
|
|
185
|
|
|
$themeData['page'] = [ |
186
|
|
|
'title' => "Fullpage Example", |
187
|
|
|
'description' => "This is the description of the page." |
188
|
|
|
]; |
189
|
|
|
|
190
|
|
|
return $this->container->theme->render($response, $view, $themeData); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
View Code Duplication |
public function getException($request, $response, $args) |
|
|
|
|
194
|
|
|
{ |
195
|
|
|
$view = 'page.html'; |
|
|
|
|
196
|
|
|
|
197
|
|
|
throw new \Exception("This is an exception"); |
198
|
|
|
|
199
|
|
|
// Get erdiko config, this gets application.json and loads the theme specified |
200
|
|
|
$themeData['theme'] = \erdiko\theme\Config::get($this->container->get('settings')['theme']); |
|
|
|
|
201
|
|
|
$themeData['page'] = [ |
202
|
|
|
'title' => "Fullpage Example", |
203
|
|
|
'description' => "This is the description of the page." |
204
|
|
|
]; |
205
|
|
|
|
206
|
|
|
return $this->container->theme->render($response, $view, $themeData); |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.