3 Tiered php - is it worth it?

I’m been using ASP.NET, more specifically one of their best practices sample applications - Issue Tracker

I really loved the way this application is constructed.

An abstract Data Access Layer class which has all the methods to retrieve your data. This class gets implemented by each data access layer, for example you might have a DAL for MySQL, and another for PostgreSql

Then there is the Business Logic Layer which has all the object definitions. Each class has static methods to retreive data from the DAL, as well as instance methods for saving, etc.

Would this be a good model to use with php? Is it worth taking the time to do this and is it easy enough?

Does anyone have an example of a 3 tiered application in php that follows a similar model?

If not this, then what is model that might suit me considering i like this one?

Look into the MVC pattern at phpPatterns. I just went through a related issue.



There are a whole bunch of ways of doing this. What is the application you have in mind?

yours, Marcus

It’s going to be an online auction site, similar to ebay.

I still say a well factored mvc app is a good candidate.

Certainly the general design you outlined is workable. The decision to use 2-N Tiers is usually dictated by the tiers themselves. I create tiers as complexity increases to improve testablity and maintainablity, or because there is a physical tier such as a separate server with an API.

I am also not sure that the whole application needs to be all the same number of tiers. For example your authentication and access controls may be 2 tier, but your auction system may be 3 or more tiers.

If you feel comfortable with the system you mentoned then go with it.


Well the MVS is a separate thing from the issue of data abstraction, and they can be used independantly.

One thing I would certainly be doing here is making use of some form of cache. Being an auction site, it would be important to invalidate the cache each time a bid is placed. The one issue here is if this site gets a lot of traffic you want make it quick, while not compromising too much of the separation of code if you are needing to distribute the application over several servers in the long run

MVC and N-Tier are orthogonal issues that can be combined. It’s not an either or relationship.

MVC relates to the interface
N-Tier relates to layers of processing

Input -> Input Controller -> Outupt/View
	Application Layer
	Domain Layer
	|	 |
	V	 V
Data Layer Infrastructure
Persistent Data (eg DB)

As far as MVC is concerned, Controller and View are at the top and everything below is the Model

As far as Tiers are concerned, each line is a seperate tier/layer (except Infrastrastructure, which is completely seperate to the DataLayer)

I realize that. However, my own N-Tier application reached a point where coding became a bit confusing. Using the MVC model, things started making more sense. I looked like the original postee already had the foundation, and grasp of concept, for N-Tier, but was lacking that extra thing that pulled it all together. I may have interpreted it wrong though…

Here is something I wrote for an article a few years back that might help you visualize the various application layers as they relate to MVC:

If you want to know how to implement the 3 Tier Architecture in PHP then take a look at the PHP/MySQL page on my website (link below) where you will find articles which document my own implementation, which in fact is a combination of 3TA and MVC (yes, they ARE different, and yes, you CAN have both at the same time).

My implementation has a single object in the Data Access Layer which allows me to switch from one DBMS to another with extreme ease.

To prove that this works and is not just a load of hot air there is a sample application on my website which you can run online, and if you are feeling adventurous you can download the source code and see how it ticks. It will run with either PHP 4 or PHP 5, and will auto-detect if you are accessing your MySQL database using the mysql_* or “improved” mysqli_* functions.

Tony Marston

A Development Infrastructure for PHP
A sample PHP application
The MVC Design Pattern for PHP

Trust me, you don’t want to click those links.

That’s extremely rude and uncalled for. Just because someone’s opinion differs from yours doesn’t warrant that response.

For applications that are not extremely large, a simplified MVC/Layerd approach such as Tony’s is better. It is easier for beginner and mid-level developers to understand this and produce an easy to understand and maintain project with a more simplified and rigid set of concepts to apply. It is also easier for new developers do understand the system when they come onto an existing project - unlike some advanced concepts that require only very advanced developers to be hired (which is unnecessary on most projects).

This attitude of ‘he doesn’t agree with everyone on this forum’ so he should be gotten rid of and not referred to is disgraceful. And not only that, by sensoring information you decrease the learning of everybody here.

Discuss rather than censor or disuade.

I agree, in general, but not in this case. I’d have banned him from my own board long ago.

Tony’s understanding of OOP is shocking. It’s only fair to warn people not to waste their time learning bad habits.

Now that would normally be a very harsh thing to say were it not for Tony’s personality - or should I say personality flaws. He’s arrogant, argumentative, and paranoid. He seems to like to stir up trouble so he can play the martyr.

Forums such as this cannot function with people like that. I respect learning, intelligent comments and polite debate. I have no respect whatsoever for Tony Marston.

Read through the above thread or his own site (if you must) but be warned there’s more to interest a professional psychologist than a professional programmer.

Banish all those blasphemers who do not worship the Mighty OOP as the one true truth. May they be doomed to spraffle the gannet for a thousand years!

– “Wee” Angus McOop, 1341


Are you still here ? , I thought you had gone and written your own BB in Ruby cos its sooooo pure. Then of course you could have banned him.

For someone who can dish out OO-Zen-Purist kak by the bucketfull (with nar’y a thought for the real world) I think you have a bit of a cheek.

It’s one thing to dislike someone or to disagree with someone’s views , another to suggest burning his/her books.

Everyone is entitled to an opinion. Even you. And Tony also

No it’s not. He promotes a simpler modelling concept that is easier to understand for those who haven’t been playing with OOP for 3+ years. Just because it doesn’t conform to your ideas don’t make it right or wrong.

The regulars took the side of someone else in these forums who arguments - while well explained and thought out - were expressed with some arrogance. So when people saw his opinion they took it as a sign from someone they respect that it is ok to shoot down Tony. Obviously in this situation, he will argue back and stand his ground in such an argumetative situation.

I don’t want to turn this thread into an argument. The point is you shouldn’t censor other peoples opinions. All of the objections from that thread are already in there. You could have put in a link to the thread and let the reader decide for themselves rather than doing what you did.

Does anybody ever look at the term OO anymore? Let me clarify…


…not Object Solidified, Object Purified, or anything else. An Object ORIENTED application may contain as few or as many objects as needed to get the job done. The lines one draws on what to encapsulate is thier own decision to make.

SHOCKER! McGruff and Marston Actually Related!

Geneologists have discovered that McGruff and Marston can both be traced back to a common ancestor – Knute Oopornot. Their Viking forefather invaded Scotland in 963. After months of sieges and pillaging, Oopornot unexpectantly headed south for a fortnight holiday in Surrey, staying at a B&B in Woking.

Unable to decide whether English or Scottish women were more beautiful, Oopornot took one of each back to his Norse home. Each bore a son, and they are the ancestors of McGruff and Marston. When old Knute died he left the older son only the family sturcture, the younger son received the inheritence. Both sons longed to return to their mother’s homelands, and by the time of the Norman Conquest both had resettled there.

Ba-dump-dump… :slight_smile: