简体   繁体   中英

CakePHP: Loading all data from database to layout.php, is that a good idea?

I have a website, where it loads all data from database and displays it in layout.php.

These data are available to whole project, to all page of that project.

Is loading data from database to layout.php a good idea? Does it make the website loading the first page slower?

Is there any alternative to loading data from database to layout.php?

1) it's perfectly fine to load data from the database into the layout. If the user needs the data, it's no different than if you load it on each action/page.

2) Yes, it makes the website loading the first page slower (at least until it's cached). How much slower varies GREATLY upon the amount of data you're retrieving and the method you're retrieving it.

3) If your data is in the database, then no - there's no alternative than to get it FROM the database. You could look at alternatives for where to store your data, but - with caching, unless you're talking about a LOT of data, it's probably not an issue... and if it IS a lot of data, you should probably re-think whether the user really needs that data on all pages.

Additional note: When you say "where it loads all data from database" - that's quite a red flag. It's rarely the case where a user needs ALL the data from the database on any page, let alone EVERY page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM