Solved

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

Posted on 2012-03-20
2
178 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 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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 30

Author Comment

by:Marco Gasi
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now