Solved

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

Posted on 2012-03-20
2
179 Views
Last Modified: 2012-06-27
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
Comment
Question by:Marco Gasi
2 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37741960
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
 
LVL 31

Author Comment

by:Marco Gasi
ID: 37742458
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question