views:

97

answers:

1

Hello Friends,

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! Cheers!

+1  A: 

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.

jimyi
Thanks very much for your help! Appreciated! But I have another question related. What to do if I take some datab from database then?
Sergio E.