There is no direct answer to your question, but there is an idea for reflection.
The difference between the problems You might think if you can separate the logic of logic and layout logic. Often, using a template engine can greatly help with this. I had positive impressions, for example, Twig or Smarty (it was some time ago, I don’t know how they are measured now). This requires you to write your code (less linear), but more logical.
A typical example of OOP, as a separation of concerns, might be something like this:
$this->setParam('Myparam','myvalue'); if ($this->isAjax()) { $this->setTemplate('ajax.php'); $this->setLayout(false); } else { $this->setTemplate('normal.php'); $this->setLayout('Mylayout'); } return $this->render();
This is an imaginary situation that can be found in many MVC-like applications and frameworks. The basic idea is that you should be able to separate your layout from your data. I would suggest taking a look at some modern frameworks for inspiration (e.g. symfony, codeigniter, zend framework).
Glossary / Commonly Used Concepts in Unleashed PHP Applications Here is a short list of concepts that you can use.
Mvc example in php: http://www.phpro.org/tutorials/Model-View-Controller-MVC.html
Note. I don't really like the implementation. I much prefer the existing framework. I like the whole explanation of this lesson. For instance. for me, this link is for learning, not for implementation.
Silex For a simple decoupled php microstructure, I would recommend silex for make symfony2. It is easy to implement and learn, but contains the basic concepts described here; and uses all the useful features of php 5.3+, such as namespace and closure.
see http://silex.sensiolabs.org/
Figure of the control panel . You have only one and only entry point for your code. I usually only have one, and only one item in your application. Typically, the frontcontroller sends a request to the rest of the application.
http://en.wikipedia.org/wiki/Front_Controller_pattern
Routing
A routing system is often used in conjunction with a frontcontroller pattern. It basically describes which URL is connected to the module / controller. This allows you to change how users access your application without changing URLs.
See: https://stackoverflow.com/questions/115629/simplest-php-routing-framework
controller
A controller is a place where buisness logic is applied. Retrieving data from a database, checking privileges, setting up a template, setting up a layout, etc. (Although this also moves outside the controller if it gets too large for a single issue).
Model The model is basically a layer in which use manages your database. It can be a simple class in which you move all your mysql_ * functions, or it can be a full-featured ORM. The basic philosophy is that all the logic associated with the extraction and placement of information in the database is shared.
One step up: ORM Relational object models, these "cartographic" SQL records for PHP objects, are a frequently used method in applications. Doctrine and Propel are two of these well-designed libraries. I rely heavily on these systems in my development. In this sense, part of the doctrine or propeller will be a model layer.
View: A view usually consists of a template engine. Some use simple PHP as a template, others, such as symfony, create a separate area in which variables are placed. There are many discussions and opinions about which is better, one of them is here in stackoverflow:
I like: - Twig: http://twig.sensiolabs.org/ - sfTemplate: http://components.symfony-project.org/templating/ - Smarty: http://components.symfony-project.org/templating/
Decoupling mechanisms:
Event Based Systems Using events in yours can help split code. For example, if you want to send an email after saving a record, events are a good solution to this; in general, the model does not need to know about email. Thus, events are a way to connect them: you can let your -email-send-class listen on certain entries so that they can send the correct email address. (Perhaps you would prefer your emails to be sent from your controller, this is probably a matter of taste).
Injection injection When using OOP code in PHP, many relied on single-element classes (configuration, etc.) running around. From the point of view of OOP, this can be considered bad, because it is difficult to test it, and it is not considered very elegant to have dependencies on it. Dependency Injection is a pattern that has appeared in Java form and is now used in new environments to get around this. It may be a little difficult to wrap around you, but you will see that it is returning in a few new frames.
Including dependencies in php: Injecting dependencies in PHP 5.3
Frames:
Many of these methods are complex or a lot of work to implement. Many will live within this. You might need a framework. You may or may not want to have a framework; this is your choice. But it’s still useful to find out how frameworks do it, and not try to reinvent the wheel yourself.
Frameless frameworks: https://stackoverflow.com/questions/694929/whats-your-no-framework-php-framework
Good habits: https://stackoverflow.com/questions/694246/how-is-php-done-the-right-way
Frames worth seeing (imho): CodeIgniter, Kahona, CakePHP, Symfony (1.4 / 2.0), Silex, Zend Franework, Yii. They are much more than their loyal fans and haters.