Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Best pracice to initialize a web application in oop (no framework)

Hi all, Experts.

I'm writing a web application and I would to know how to initilize all constant (such as db connection data, directories etc), classes and so on.

I read about bootstrap file but I'm not sure to understand the tecnique ( more details here: http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_27638280.html#a37740820).

Thanks to all in advance.

Cheers
0
Marco Gasi
Asked:
Marco Gasi
1 Solution
 
Ray PaseurCommented:
I don't adhere to rigidly to OOP principles; I use them when it helps make things clear and use procedural code when that is the easiest way to get results.  My general design pattern goes like this:

// ON EVERY PAGE AND SCRIPT
require_once('common.php');

That include() starts the session, connects and selects the data base, initializes all the constants and variables, sets the timezone, etc.  In other words, all of the housekeeping is done with a single line of code.  That script also contains all of my class and function definitions.  In the case of some sites, it is a fairly big file (perhaps 50K) but since it is all in one script file and uses no autoloaders, it is very fast.  Obviously version control is important here.  If I were in a development and debugging mode, I might consider using several "common.php" scripts to isolate functionality and create independence between things that are being separately developed.  But once I am fairly sure that all the parts work correctly, I put them together into a single common file.

If it is a web service (not a web page) that is all the initialization I need, and there is no client HTML output.  If is is a web page, I have two other statements that are required.

require_once('header.php');
// PAGE GETS CREATED HERE
require_once('footer.php');

In between those two, I put the PHP and HTML that generate the web page.
0
 
Marco GasiFreelancerAuthor Commented:
Hi, Ray. Thank you very mutch for your answer. Probably you have read yet my comment in my other question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_27638280.html#a37740820). If not, please, refer to that.

Thank you again

Cheers
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now