3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\View\Helper
;
12 use Zend\View\Exception
;
13 use Zend\View\Model\ModelInterface
as Model
;
16 * View helper for retrieving layout object
18 class Layout
extends AbstractHelper
23 protected $viewModelHelper;
26 * Set layout template or retrieve "layout" view model
28 * If no arguments are given, grabs the "root" or "layout" view model.
29 * Otherwise, attempts to set the template for that view model.
31 * @param null|string $template
34 public function __invoke($template = null)
36 if (null === $template) {
37 return $this->getRoot();
40 return $this->setTemplate($template);
48 public function getLayout()
50 return $this->getRoot()->getTemplate();
54 * Get the root view model
56 * @throws Exception\RuntimeException
59 protected function getRoot()
61 $helper = $this->getViewModelHelper();
63 if (!$helper->hasRoot()) {
64 throw new Exception\
RuntimeException(sprintf(
65 '%s: no view model currently registered as root in renderer',
70 return $helper->getRoot();
76 * @param string $template
79 public function setTemplate($template)
81 $this->getRoot()->setTemplate((string) $template);
86 * Retrieve the view model helper
90 protected function getViewModelHelper()
92 if (null === $this->viewModelHelper
) {
93 $this->viewModelHelper
= $this->getView()->plugin('view_model');
96 return $this->viewModelHelper
;