You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.7 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
12 years ago
10 years ago
12 years ago
12 years ago
  1. <?php namespace Majestic\Layout;
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage Layout
  7. * @since 2010-02-25
  8. */
  9. abstract class Layout
  10. {
  11. protected $template;
  12. /**
  13. * @var \Majestic\View\PHPView
  14. */
  15. protected $view;
  16. public function __construct()
  17. {
  18. $this->view = \Majestic\App\FrontController::getInstance()->getView();
  19. }
  20. /**
  21. * @param string $name
  22. * @param \Majestic\App\Action $action
  23. */
  24. protected function assign($name, $action)
  25. {
  26. $this->view->assign($name, $action->fetch());
  27. }
  28. /**
  29. * @param string $name
  30. * @param \Majestic\App\Action $action
  31. */
  32. protected function append($name, $action)
  33. {
  34. $this->view->append($name, $action->fetch());
  35. }
  36. /**
  37. * @param string $name
  38. * @param \Majestic\App\Action $action
  39. */
  40. protected function prepend($name, $action)
  41. {
  42. $this->view->prepend($name, $action->fetch());
  43. }
  44. abstract protected function execute();
  45. /**
  46. * Execute Action, insert action's result html into layout template and return Layout html
  47. * @param \Majestic\App\Action $action
  48. * @return string
  49. */
  50. public function fetch($action)
  51. {
  52. $this->view->assign('content', $action->fetch());
  53. $this->execute();
  54. return $this->view->fetch($this->getTemplate());
  55. }
  56. /**
  57. * Return content of template
  58. * @return string
  59. */
  60. protected function getTemplate()
  61. {
  62. $template = ($this->template) ? $this->template : substr(get_class($this), 0, -6/*strlen('Layout')*/);
  63. return '/layouts/' . $template;
  64. }
  65. }