View Helpers are also a good idea. I had a ecommerce website, which I had a layout.phtml with menus with categories and subcategories that I needed to bring from the database.
For this, I did the following:
Bootstrap.php:
protected function _initHelperPath()
{
$view = $this->bootstrap('view')->getResource('view');
$view->setHelperPath(APPLICATION_PATH . '/views/helpers', 'View_Helper');
}
application.ini:
resources.view[]=
In views/helpers, I had a file called Menus:
class View_Helper_Menus extends Zend_View_Helper_Abstract {
public function categories(){
$categories = new Application_Model_DbTable_Categories();
return $categories->fetchAll();
}
public function subCategories(){
$subCategories = new Application_Model_DbTable_SubCategories();
return $subCategories->fetchAll();
}
}
In layout.phtml, I just had to call the specific helper, and call the methods from it:
$menu = $this->getHelper('Menus');
$categories = $menu->categories();
$subCategories = $menu->subCategories();
Hope it helps someone that needs to bring data from database to render the layout.