开发者

Zend Framework, The best way to implement layout

I'm learning ZF for two weeks so far. Like it so much. I'd like to ask, what is the best practice for layouts? I got one layout and I need to include few variables for it. Do I need to do this in every controller?

The second question is about hiding one part of the layout. Currently I'm doing this as following:

if(Zend_Controller_Front::getInstance()->getRequest()->getControllerName() !== 'page') { ?>
    <div>
      This div should be displayed only on one page
    </div>
<?php } ?>

Is this a good practice? Maybe you could share your own?

Thanks in advance for any replies and comments! Che开发者_运维百科ers!


You can set the variables for your layout in the bootstrap:

protected function _initViewVars() {
    $this->bootstrap('view');
    $view = $this->getResource('view');
    $view->myvar = 'test';
}

You would then be able to access it with $this->myvar in the layout.

For your 2nd question, I would set a view variable inside the controller to indicate that a section of the layout should be hidden.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜