views:

43

answers:

2

For example i have echo $this->escape($this->test); in index.phtml and in controller $this->view->test = 'test message';, but i want to do this from bootstrap, becouse i want to show Form in every page (controller).

A: 

sorry i made it

    $view = new Zend_View;
    $view->setBasePath(APPLICATION_PATH . "/views");
    $view->arr = 'message';
    echo $view->render('test.php');
Ivelin Popov
A: 
protected function _initView()
{
    $this->view = new Zend_View();
    $this->view->test = 'test message';
    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer'); 
    $viewRenderer->setView($this->view);
}

But I would recommend doing this in a controller plugin, not during the bootstrap:

<?php
class My_Controller_Plugin_AddSomethingToViewInAllControllerActions extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch()
    {
        $viewRenderer = Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer');
        $viewRenderer->initView();
        $view = $viewRenderer->view;

        $view->test = 'test message';
    }
}
Richard Knop