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.

52 lines
1.1 KiB

  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. abstract protected function execute();
  31. /**
  32. * @param Action $action
  33. */
  34. public function fetch($action)
  35. {
  36. $this->view->assign('content', $action->fetch());
  37. $this->execute();
  38. return $this->view->fetch($this->getTemplate());
  39. }
  40. protected function getTemplate()
  41. {
  42. $template = ($this->template) ? $this->template : substr(get_class($this), 0, -6/*strlen('Layout')*/);
  43. return '/layouts/' . $template;
  44. }
  45. }