What are the main components of a PHP application? I’ve come up with these:
- Database
- HTML templates
- Sessions/Cookies/Authentication
- User Input ($_GET or $_POST or URL segments)
Are these the main components or are there any others?
The reason I’m asking this is so I can put each ‘Object’ in its own class without having to worry about how it will be technically feasible. For example, I can have a Post class which allows you to add posts to a blog, without having to worry about how it will fit in with the rest of the system / php language, etc.
This sounds a lot like this question.
I would strongly recommend that you take a look at Patterns of Enterprise Application Architecture by Martin Fowler.
I would also recommend that you search for questions on this site related to the Model or Domain as well as Object Relational Mapping or Database Abstraction. I happen to know that there is a great deal of excellent content particularly in regard to PHP.
I see two questions in this question that you’ve posted. First, what are the general architectural components of a site. Generally you’ll have these three in some manifestation:
Second question I see is where to place handling of a specific business object in the application. This is where the discussion gets a little more involved because I assume that you need to interact with Posts both as business objects (within the domain) and as rows in a database table. Both of these concerns can be wrapped inside of the same class utilizing a pattern called Active Record which has been popularized by Ruby on Rails. However, depending on the complexity of the application and database involved you may want to consider separating the business logic from the database interaction by creating one Post class that acts as the database interaction layer and another Post class that contains all of the business logic.