We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Guidance setting global variables from database.

Hi,

I am new to OOP and also Phalcon. I am creating a multi site website, When a user accesses the site I need to get settings based on there url from the database (eg contact details etc). What would be the best way to initiatiate this (ie. where should I trigger this request eg. config.php? , and how should I trigger the request upon the user accessing the site eg should i use a function initialize?), also would it be best to store these settings in a session, and finally I want this script to be triggered once only when the user accesses the site and not at every page request what would be recommened to achieve this?

Thanks



51.2k

If the data doesn't change frequently, a configuration file would be better. If it does change frequently, you can store it in database, but use a caching layer to avoid querying the DB on every request.