?
Solved

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

Posted on 2012-03-20
2
Medium Priority
?
189 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
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…
Suggested Courses

770 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