Quick search:

Composition by inclusion and callback pattern

This pattern is behind the page composition of phpPeanuts. It builds on the fact that the code from the included file is executed inside the function it is included from. For example let's say we have in 'myScript.php':

    $page = new MyPage();

in 'MyPage.class.php':


class MyPage {

    function service() {

    function printTitle() {
    print "My Page";

    function printBodyPart() {
    $part = new MyBodyPart();

in 'MyPage.skin.php':

    <TITLE><? $this->printTitle() ?></TITLE>
    <?php $this->printBodyPart() ?>

in 'MyBodyPart.class.php':

class MyBodyPart {

    function service() {

    function printMessage() {
    print "Hello World";

in 'MyBodyPart.skin.php':

<B><?php $this->printMessage() ?></B>

Becuase the skin files are included inside methods, the $this variable will reference the object whose method includes the skin. This way we get:
- separation of layout and OOP code,
- pages composed from reusable parts
And all this without a framework, without a template engine, all you need is to follow a simple pattern!

N.B. phpPeanuts uses different naming conventions for class and skin files.
P.S. The user interface of pnt/unit is a more complete example following this pattern (pht/uint does not use any framework code except pnt/generalfunctions.php)