This repository was archived by the owner on Jun 18, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +49
-6
lines changed Expand file tree Collapse file tree 4 files changed +49
-6
lines changed Original file line number Diff line number Diff line change 3
3
namespace App \Controllers ;
4
4
5
5
use App \DI ;
6
+ use App \Models \Page ;
7
+ use Dewep \Exception \HttpException ;
6
8
use Dewep \Http \Request ;
7
9
8
10
/**
@@ -25,7 +27,8 @@ public function index(Request $request): string
25
27
return DI ::twig ()->render (
26
28
'page.html.twig ' ,
27
29
[
28
- 'name ' => 'home ' ,
30
+ 'title ' => 'Home ' ,
31
+ 'text ' => 'This is - Home ' ,
29
32
]
30
33
);
31
34
}
@@ -35,16 +38,31 @@ public function index(Request $request): string
35
38
* @param string $id
36
39
*
37
40
* @return string
41
+ * @throws HttpException
38
42
* @throws \Twig\Error\LoaderError
39
43
* @throws \Twig\Error\RuntimeError
40
44
* @throws \Twig\Error\SyntaxError
41
45
*/
42
46
public function page (Request $ request , string $ id ): string
43
47
{
48
+ $ query = <<<'SQL'
49
+ SELECT * FROM `page` WHERE `id`=:id;
50
+ SQL;
51
+
52
+ /** @var Page|false $page */
53
+ $ page = DI ::db ()->select ($ query , [':id ' => (int )$ id ])
54
+ ->asClass (Page::class)
55
+ ->getOne ();
56
+
57
+ if (!$ page instanceof Page) {
58
+ throw new HttpException ('Page not found ' , 404 );
59
+ }
60
+
44
61
return DI ::twig ()->render (
45
62
'page.html.twig ' ,
46
63
[
47
- 'name ' => $ id ,
64
+ 'title ' => $ page ->getTitle (),
65
+ 'text ' => $ page ->getText (),
48
66
]
49
67
);
50
68
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace App ;
4
4
5
+ use Dewep \Http \Response ;
6
+
5
7
/**
6
8
* Class HttpCodes
7
9
*
10
12
class HttpCodes
11
13
{
12
14
/**
15
+ * @param array $error
16
+ *
13
17
* @return string
14
18
* @throws \Twig\Error\LoaderError
15
19
* @throws \Twig\Error\RuntimeError
16
20
* @throws \Twig\Error\SyntaxError
17
21
*/
18
- public static function httpCode404 (): string
22
+ public static function httpCode404 (array $ error ): string
19
23
{
20
- return DI ::twig ()->render ('404.html.twig ' , []);
24
+ return DI ::twig ()->render (
25
+ '404.html.twig ' ,
26
+ [
27
+ 'text ' => $ error ['errorMessage ' ] ?? 'Error 404 ' ,
28
+ ]
29
+ );
21
30
}
22
31
}
Original file line number Diff line number Diff line change 1
- Page not found
1
+ <!DOCTYPE html>
2
+ <html >
3
+ <head >
4
+ <title >404</title >
5
+ </head >
6
+ <body >
7
+ {{ text }}
8
+ </body >
9
+ </html >
Original file line number Diff line number Diff line change 1
- {{ name }}
1
+ <!DOCTYPE html>
2
+ <html >
3
+ <head >
4
+ <title >{{ title }}</title >
5
+ </head >
6
+ <body >
7
+ {{ text }}
8
+ </body >
9
+ </html >
You can’t perform that action at this time.
0 commit comments