开发者

Zend Framework: How to make view from bootstrap.php

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


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';
    }
}


sorry i made it

    $view = new Zend_View;
    $view->setBasePath(APPLICATION_PATH . "/views");
    $view->arr = 'message';
    echo $view->render('test.php');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜