Zend Framework: var view set in bootstrap not available in view scripts?

I have set the var view in the bootstrap file like this:

protected function _initVars()
{
    $this->bootstrap('layout');
    $layout = $this->getResource('layout');
    $view = $layout->getView();
    $view->theme = 'MY_THEME';
}

      

My application.ini also has the following line:

resources.view[] =

      

But inside view scripts,

<?php echo $this->theme ?> 

      

prints nothing.

Please suggest?

Edit

I could use all the functions, but these are variables of the kind that don't get echoed for some reason.

+2


a source to share


3 answers


You forgot to return your viewer. return $ view;



+1


a source


Boostraping View with init method works for me



protected function _initView()
{
    $view = new Zend_View;
    $view->setEncoding('UTF-8');
    $view->doctype('XHTML1_TRANSITIONAL');

    $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
    Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);

    $view->SOME_VAR = 'SOME_VALUE';

    return $view;
}

      

0


a source


It's mine and works great for me ............. i hope it helps

 protected function _initLayoutView() {
            $this -> bootstrap ('layout');
            $layout = $this -> getResource ('layout');
            $view = $layout -> getView();
            $view->addHelperPath('dagho/View/Helper', 'dagho_View_Helper');
            $view -> doctype('XHTML1_STRICT');
            $view->headMeta()->appendHttpEquiv('Content-Type',
                    'text/html; charset=utf-8')
                   ->appendHttpEquiv('Content-Language', 'en-US');;
            $view->headLink(array('rel' => 'favicon',
                    'href' => $view->baseUrl().'/img/favicon.ico'),
                    'PREPEND');
            $view -> headLink() -> prependStylesheet($view->baseUrl('/css/demo.css'))
                    ->prependStylesheet($view->baseUrl('/css/text.css'))
                    ->prependStylesheet($view->baseUrl('/css/960.css'))
                    ->prependStylesheet($view->baseUrl('/css/reset.css'));

            $view->headScript()->appendFile($view->baseUrl('js/jquery-1.4.2.min.js') , "text/javascript")
                    ->appendFile($view->baseUrl('js/jquery-ui.min.js') , "text/javascript")
                    ->appendFile($view->baseUrl('js/swfobject/swfobject.js') , "text/javascript");
            $view -> headTitle('title ');
            $view -> headTitle() -> setSeparator( ' : ' );
            $trackerId = 'UA-xxxxxxxx-4';
            $googleAnalytics = $view->GoogleAnalytics($trackerId);
            return $view ;
        }

      

and in the view, for example, I do something like: <?php echo $this->GoogleAnalytics(); ?>

anyway you can add the last semicolon in <?php echo $this->theme ?>

like <?php echo $this->theme; ?>

I know the sound is crazy, but I prefer to stick to the rules

0


a source







All Articles