Solved

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

Posted on 2012-03-20
2
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 110

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

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!

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

733 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