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.

78 lines
1.6 KiB

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