Link to home
Start Free TrialLog in
Avatar of gublooo
gubloooFlag for India

asked on

Zend Framework - loading data at startup

Hello

I am new to Zend and am trying to learn what are the best practices.
One of the things I am doing is loading all the menu items from the database - that will be shown in all the pages of the website.

Now instead of pulling the items everytime - I want to pull the items once and store them in the session or namespace and just read it from the session and display it everytime the page is accessed.

At which place am I supposed to load this data from DB and store in session. Should this be done in bootstrap.php - It cant be done in the main index controller as a user might now always come from the main page.

So it advisable to load such things in the bootstrap.php or how else is it done.

Thanks
Avatar of r2d2_PL
r2d2_PL

Hello,

Session is supposed to store per-user variables (like login state) not menu items that'll be same for all users. In fact you should limit session data, by limit i mean not making 1092 copies of same "thing", just to show it later.

All you'll do is slowing everything down. mySQL have its own cache, so there's no need to keep static queries in additional cache if they're as simple as fetching a couple of menu items.
Avatar of gublooo

ASKER

I agree but are you recommending that I pull these menu items from the database every time a page is requested. In Zend that would mean, every controller should be fetching these menu items. Somehow that doesn't sound right.

Like for example the database connection is setup once and stored in the Zend::Registry in the bootstrap.php file.

Can't we do something like that here.
Thanks
ASKER CERTIFIED SOLUTION
Avatar of r2d2_PL
r2d2_PL

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial