Imho they are both _very_ different..
The first example has the approach where the specific code includes the common code...
The second example has the approach where the common code includes the specific code...
(In OOP this problem is known as has_a versus is_a)
I choose for a third approach, a mix of both (like .net masterpages or java tiles) This way you can easily change the "common" part but without that all your pages are dependant of it. (Offcourse there are OOP implementations of this approach possible)
Code: Select all
<?php
// specific1.php
$page['body'] = '/specific1.html';
include('common.php');
?>
Code: Select all
<?php
// specific2.php
$page['title'] = 'some title';
$page['body'] = '/spefic2.html';
include('common.php');
?>
Code: Select all
<?php
// common.php
// load default values if they aren't overriden
if (!isset($page['title']) $page['title'] = 'default title';
if (!isset($page['body']) $page['body'] = 'default_body.html';
header('Content-Type: text/html');
?>
<html>
<head>
<title><?php echo $page['title']; ?></title>
</head>
<body>
<?php readfile($page['body']); ?>
</body>
</html>
Another example of masterpage:
http://timvw.madoka.be/?p=431
And a possible OOP implementation:
http://timvw.madoka.be/?p=426