nourdine
nourdine

Reputation: 7597

view loading "by hand" in zend

I am using the zend framework and trying to create and render a view from inside a controller. Normally this process is handled by the framework but I thought I could do it myself too as this part of the documentation states.

Unfortunately there is something wrong as the framework is still trying to load the default view as well. Here's my controller

<?php

class ViewController extends Zend_Controller_Action {

    private $viewsFolder = null;

    public function init()
    {
        $this->viewsFolder = realpath(dirname(__FILE__)) . '/../views/custom/';
    }

    public function indexAction()
    {

        // using a custom view (initialization and rendering executed by hand)
        $view = new Zend_View();

        $view->setScriptPath($this->viewsFolder);

        $view->assign(array(
            "dev_name" => "Fabs",
            "framework" => "Zend frmwrk"
        ));

        echo $view->render('customView.phtml');
    }
}

and here is the error I get

Message: script 'view/index.phtml' not found in path (/home/ftestolin/stuff/rubrica/application/views/scripts/)

It looks like the normal view rendering cannot be suppressed. Any idea how to do it?

Upvotes: 2

Views: 580

Answers (2)

David Weinraub
David Weinraub

Reputation: 14184

Probably better to disable the ViewRenderer rather than remove it. In controller:

$this->_helper->viewRenderer->setNoRender(true);

Remember that the ViewRenderer is where Zend_Form instances pull their default view for their own rendering. Removing the ViewRenderer means that it has to be re-instantiated later when the form needs to render. But when it does so, it recreates a brand new Zend_View instance. Any settings you have applied to your view - say, at bootstrap, setting doctype, etc - will be lost.

Upvotes: 1

nourdine
nourdine

Reputation: 7597

ok I will answer myself :)

one has to prevent the normal behaviour which is handled by Zend_Controller_Action_Helper_ViewRenderer

you can do it like that in the controller and then do your View instantiation business.

$this->_helper->removeHelper('viewRenderer'); // stop the default views rendering process

cheers

Upvotes: 0

Related Questions