1 | <?php |
||
2 | |||
3 | namespace Pan\Home; |
||
4 | |||
5 | use Anax\Commons\ContainerInjectableInterface; |
||
6 | use Anax\Commons\ContainerInjectableTrait; |
||
7 | |||
8 | |||
9 | // use Anax\Route\Exception\ForbiddenException; |
||
10 | // use Anax\Route\Exception\NotFoundException; |
||
11 | // use Anax\Route\Exception\InternalErrorException; |
||
12 | |||
13 | /** |
||
14 | * A sample controller to show how a controller class can be implemented. |
||
15 | */ |
||
16 | class HomeController implements ContainerInjectableInterface |
||
17 | { |
||
18 | use ContainerInjectableTrait; |
||
19 | |||
20 | |||
21 | |||
22 | /** |
||
23 | * @var $data description |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
24 | */ |
||
25 | private $currentUser; |
||
0 ignored issues
–
show
|
|||
26 | private $db; |
||
27 | |||
28 | |||
29 | |||
30 | // /** |
||
31 | // * The initialize method is optional and will always be called before the |
||
32 | // * target method/action. This is a convienient method where you could |
||
33 | // * setup internal properties that are commonly used by several methods. |
||
34 | // * |
||
35 | // * @return void |
||
36 | // */ |
||
37 | public function initialize() : void |
||
38 | { |
||
39 | // Connect the database |
||
40 | $this->db = $this->di->get("db"); |
||
41 | $this->db->connect(); |
||
42 | } |
||
43 | |||
44 | |||
45 | |||
46 | /** |
||
47 | * Show all items. |
||
48 | * |
||
49 | * @return object as a response object |
||
50 | */ |
||
51 | public function indexActionGet() : object |
||
52 | { |
||
53 | $page = $this->di->get("page"); |
||
54 | |||
55 | $sql = "SELECT * FROM posts order by created desc;"; |
||
56 | $posts = $this->db->executeFetchAll($sql); |
||
57 | |||
58 | $sql = "SELECT * FROM tags ORDER BY tagname asc limit 5;"; |
||
59 | $tags = $this->db->executeFetchAll($sql); |
||
60 | //var_dump($tags); |
||
61 | $sql = "SELECT * FROM users;"; |
||
62 | $users = $this->db->executeFetchAll($sql); |
||
63 | |||
64 | $page->add("home/index", [ |
||
65 | "tags" => $tags, |
||
66 | "posts" => $posts, |
||
67 | "users" => $users, |
||
68 | ]); |
||
69 | |||
70 | return $page->render([ |
||
71 | "title" => "The home page ", |
||
72 | ]); |
||
73 | } |
||
74 | } |
||
75 |