Issues

ZF-1198: Zend_View - support layouts.

Description

Zend_Vew should to support layouts (like in RoR, CakePHP etc.)

My proposal is to create Zend_View::registerParentScript($view, $contentVariableName);

$view is script file used as a layout. $contentVariableName is name of variable that will be used as a holder of rendered child scripts.

Additional methods: Zend_View::isParentViewRegistered() // boolean Zend_View::getContentVariableName(); // string etc.

If it does not fit Zend Framework View philosphy, maybe it there is a place to implement that in Zend_Controller_Action::initView()?

Comments

??If it does not fit Zend Framework View philosphy, maybe it there is a place to implement that in Zend_Controller_Action::initView()???

Maybe I wrote that too fast.

But this is my implementation of what I want:


    public function render($action = null, $name = null, $noController = false)
    {
        if (null === $action) {
            $action = $this->getRequest()->getActionName();
        } elseif (!is_string($action)) {
            throw new Zend_Controller_Exception('Invalid action specifier for view render');
        }

        $view   = $this->initView();
        $script = $action . '.' . $this->viewSuffix;

        if (!$noController) {
            $script = $this->getRequest()->getControllerName() . DIRECTORY_SEPARATOR . $script;
        }
        $layout = $this->getBasePath() . 'layout' . $this->viewSuffix;
        if (file_exists($layout) {
            /* $content_for_layout is equivalent of mentioned
                in my first post $contentVariableName */
            $view->content_for_layout = $view->render($script);
            $script = $layout;
        };
        $this->getResponse()->appendBody(
            $view->render($script),
            $name
        );
    }

Assign to Matthew.

The Zend_Layout proposal was accepted, and an implementation exists in the incubator at this time. Please test and provide feedback on the fw-mvc list.

Zend_Layout is scheduled for release with the 1.1.0 release.

Zend_Layout and all related functionality merged to core in r7078.