I’m writing my first PHP app. Everyone talks about having a bootstrap.php to initialize your app. This makes sense and I’ve put together one that I’m happy with. There’s two things I don’t understand, and which no one seems to mention:
-
Where do I call my boostrap from? Do I include it in every page? Please tell me there’s a better way…
-
How do I make it so my bootstrap is not called more often than needed? I assume it only needs to be called either at the start of the app or the start of a new session.
1: Generally the bootstrap is in the “application” directory. It is called from the “public” directory which is in the same level as application (not inside of it). The index.php inside the public folder should include the bootstrap.php and that is where your Document_Root should be set to (note you may need to change / add some include paths for it to work)
2: It should only be included once via the index.php file in the public folder. Just including it there should be enough, if it was done correctly.
Hope that helps.