Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <?php
  2.  
  3. namespace controllers;
  4.  
  5. use core\View;
  6. use core\Database;
  7. use models\Articles;
  8.  
  9. class ArticlesController
  10. {
  11.  
  12. private $view;
  13.  
  14. private $db;
  15.  
  16. public function __construct()
  17. {
  18. $this->view = new View('app');
  19. $this->db = new Database();
  20. }
  21.  
  22. public function view(int $articleId)
  23. {
  24. $result = $this->db->query(
  25. 'SELECT * FROM `articles` WHERE id = :id;',
  26. [':id' => $articleId],
  27. Articles::class
  28. );
  29.  
  30. if ($result === []) {
  31. $this->view->renderHtml('../templates/error/404.php', [], 404);
  32. return;
  33. }
  34.  
  35. $user = $this->db->query(
  36. 'SELECT `nickname` FROM `users` WHERE id = :id',
  37. [':id' => $result[0]['author_id']],
  38. Articles::class
  39. );
  40.  
  41. if ($user === []) {
  42. $user[0]['nickname'] = 'Неизвестно';
  43. }
  44.  
  45. $this->view->renderHtml('views/Articles.php', ['article' => $result[0], 'nickname' => $user[0]['nickname']]);
  46. }
  47.  
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement