如何在ZF2中的每个页面上运行一个函数

I'm new to ZEND so go easy, I have a menu table set up in mysql called menu_table, how do I run a function on every page to select * from that table and then pass it through to Module/Application/View/layout/layout.phtml

Many thanks

The best practice in this case would be to create custom View Helper to get all menu items from the menu_table.

  • In custom View Helper you have to inject service or mapper with method to get all data
  • Custom View Helper should call from layout.phtml