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
|
|
|
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
|
|
View Code Duplication |
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
|
|
|
/** |
128
|
|
|
* Leverage the theme trait to easily add content to an action |
129
|
|
|
*/ |
130
|
|
View Code Duplication |
public function getAbout($request, $response, $args) |
|
|
|
|
131
|
|
|
{ |
132
|
|
|
$this->getThemeEngine(); |
133
|
|
|
$this->theme->title = "About"; |
134
|
|
|
$this->theme->description = "Erdiko is a framework and set of open source packages for lean php development. |
135
|
|
|
Created by Arroyo Labs and community contributors with the help of Slim and Symfony components"; |
136
|
|
|
|
137
|
|
|
return $this->render($response, null, $theme); |
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Test the session |
142
|
|
|
*/ |
143
|
|
|
public function getSession($request, $response, $args) |
|
|
|
|
144
|
|
|
{ |
145
|
|
|
$this->getThemeEngine(); |
146
|
|
|
$this->theme->title = "Session Test"; |
147
|
|
|
|
148
|
|
|
$value = (isset($_GET["index"])) ? $_GET["index"] : \erdiko\session\Session::get('index'); |
|
|
|
|
149
|
|
|
\erdiko\session\Session::set('index', $value); |
150
|
|
|
|
151
|
|
|
// $this->container->logger->debug("session::index = ".\erdiko\session\Session::get('index')); |
|
|
|
|
152
|
|
|
$this->theme->description = "Session value: ".\erdiko\session\Session::get('index'); |
|
|
|
|
153
|
|
|
|
154
|
|
|
return $this->render($response, null, $theme); |
|
|
|
|
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function getFlash($request, $response, $args) |
158
|
|
|
{ |
159
|
|
|
$view = 'page.html'; |
160
|
|
|
|
161
|
|
|
// Add some flash messages |
162
|
|
|
$this->container->flash->addMessage('success', 'This is a success message'); |
163
|
|
|
$this->container->flash->addMessage('info', 'This is an info message'); |
164
|
|
|
$this->container->flash->addMessage('warning', 'This is a warning message'); |
165
|
|
|
$this->container->flash->addMessage('danger', 'This is a danger (error) message'); |
166
|
|
|
|
167
|
|
|
// Get erdiko config, this gets application.json and loads the theme specified |
168
|
|
|
$themeData['theme'] = \erdiko\theme\Config::get($this->container->get('settings')['theme']); |
|
|
|
|
169
|
|
|
$themeData['args'] = $args; |
170
|
|
|
$themeData['page'] = [ |
171
|
|
|
'title' => "Flash Message Example" |
172
|
|
|
]; |
173
|
|
|
|
174
|
|
|
return $this->container->theme->render($response, $view, $themeData); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function getGrid($request, $response, $args) |
178
|
|
|
{ |
179
|
|
|
$this->container->logger->debug("/controller"); |
180
|
|
|
$view = 'examples/grid.html'; |
181
|
|
|
|
182
|
|
|
// Get erdiko config, this gets application.json and loads the theme specified |
183
|
|
|
$themeData['theme'] = \erdiko\theme\Config::get($this->container->get('settings')['theme']); |
|
|
|
|
184
|
|
|
// $this->container->logger->debug("config: ".print_r($config, true)); |
|
|
|
|
185
|
|
|
|
186
|
|
|
// Generate data for grid |
187
|
|
|
$item = [ |
188
|
|
|
'url' => "#", |
189
|
|
|
'image' => "/images/grid-item.png", |
190
|
|
|
'name' => "Item" |
191
|
|
|
]; |
192
|
|
|
$items = array(); |
193
|
|
|
$max = (int)$args['param']; |
194
|
|
|
$this->container->logger->debug("param: ".$max); |
195
|
|
|
|
196
|
|
View Code Duplication |
for($i = 0; $i < $max; $i++) { |
|
|
|
|
197
|
|
|
$item['name'] = "Item $i"; |
198
|
|
|
$items[] = $item; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
$themeData['page'] = [ |
202
|
|
|
'title' => "Grid Example", |
203
|
|
|
'items' => $items |
204
|
|
|
]; |
205
|
|
|
|
206
|
|
|
return $this->container->theme->render($response, $view, $themeData); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
View Code Duplication |
public function getFullpage($request, $response, $args) |
|
|
|
|
210
|
|
|
{ |
211
|
|
|
$view = 'fullpage.html'; |
212
|
|
|
|
213
|
|
|
// Get erdiko config, this gets application.json and loads the theme specified |
214
|
|
|
$themeData['theme'] = \erdiko\theme\Config::get($this->container->get('settings')['theme']); |
|
|
|
|
215
|
|
|
$themeData['page'] = [ |
216
|
|
|
'title' => "Fullpage Example", |
217
|
|
|
'description' => "This is the description of the page." |
218
|
|
|
]; |
219
|
|
|
|
220
|
|
|
return $this->container->theme->render($response, $view, $themeData); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
View Code Duplication |
public function getException($request, $response, $args) |
|
|
|
|
224
|
|
|
{ |
225
|
|
|
$view = 'page.html'; |
|
|
|
|
226
|
|
|
|
227
|
|
|
throw new \Exception("This is an exception"); |
228
|
|
|
|
229
|
|
|
// Get erdiko config, this gets application.json and loads the theme specified |
230
|
|
|
$themeData['theme'] = \erdiko\theme\Config::get($this->container->get('settings')['theme']); |
|
|
|
|
231
|
|
|
$themeData['page'] = [ |
232
|
|
|
'title' => "Fullpage Example", |
233
|
|
|
'description' => "This is the description of the page." |
234
|
|
|
]; |
235
|
|
|
|
236
|
|
|
return $this->container->theme->render($response, $view, $themeData); |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.