开发者

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

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开发者_如何学Python.

Please suggest?

Edit

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


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


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


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜