Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. class Controller
  2. {
  3. protected $db;
  4. private $article;
  5. private $nav;
  6.  
  7. public function __construct($db)
  8. {
  9. $this->db = $db;
  10. $this->article = new Article($this->db);
  11. $this->nav = new Nav($this->db);
  12. }
  13.  
  14. public function render($template)
  15. {
  16. var_dump($this->article->getRow());
  17. var_dump($this->nav->getRows());
  18. }
  19.  
  20. }
  21.  
  22. class Controller
  23. {
  24. private $container;
  25.  
  26. public function __construct()
  27. {
  28. }
  29.  
  30. public function render($container,$template)
  31. {
  32. $this->container = $container;
  33. var_dump($this->container->getArticle($url = 'home'));
  34. var_dump($this->container->getNav());
  35. }
  36.  
  37. }
  38.  
  39. class Container
  40. {
  41. protected $db;
  42. private $article;
  43. private $nav;
  44.  
  45. public function __construct($db)
  46. {
  47. $this->db = $db;
  48. }
  49.  
  50. public function setArticle()
  51. {
  52. if (is_null($this->article))
  53. {
  54. $this->article = new Article($this->db);
  55. }
  56. return $this->article;
  57. }
  58.  
  59. public function setNav()
  60. {
  61. if (is_null($this->nav))
  62. {
  63. $this->nav = new Nav($this->db);
  64. }
  65. return $this->nav;
  66. }
  67.  
  68. public function getArticle($url)
  69. {
  70. return $this->setArticle()->getRow($url);
  71. }
  72.  
  73. public function getNav()
  74. {
  75. return $this->setNav()->getRows();
  76. }
  77. }
  78.  
  79. class Article
  80. {
  81. public function __construct($db)
  82. {
  83.  
  84. }
  85.  
  86. public function getRow($url)
  87. {
  88. return "row 1";
  89. }
  90. }
  91.  
  92. class nav
  93. {
  94. public function __construct($db)
  95. {
  96.  
  97. }
  98.  
  99. public function getRows()
  100. {
  101. return "rows nav";
  102. }
  103. }
  104.  
  105. $db = 'pdo connection';
  106. $template = 'template.phtml';
  107. $container = new Container($db);
  108. $controller = new Controller();
  109. $controller->render($container,$template);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement