views:

197

answers:

3

I've set a view var in bootstrap file like this:

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

My application.ini has following line as well:

resources.view[] =

But inside view scripts,

<?php echo $this->theme ?> 

prints nothing.

Please suggest?

Edit

I could use all the functions but it is view variables which are not getting echoed, for some reason.

A: 

Boostraping the View via an 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;
}
Goran Jurić
@Goran Jurić: Your solution doesn't work in my case. Also, It'd be good if I could know the actual problem in my case.
understack
A: 

This is mine and works great for me ............. i hope it help

 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(); ?> any way can you add the last semicolon in the to <?php echo $this->theme ?> be like <?php echo $this->theme; ?> i know sounds crazy but i prefer to stick with rules

tawfekov
@tawfekov: I also use most of the functions you mentioned above without any problem. Only view variables are not getting printed in view scripts.
understack
@understack so this is really wired issue , if you need fast solution use zend registry but i don't like to use unless i need to btw what is your ZF version ?
tawfekov
+1  A: 

You forgot to return your view object. return $view ;

Iznogood
agreed, return $view from _initVars()
jah