QUOTE
yeah, 3 hours 'away.' just let me say that i don't appreciate the fact that php is embedded in existing html documents. I kinda like the seperation between .aspx pages and the underlying code. slipping code between embedded tags just don't do it for me, i gotta say. i'll learn to cope, but that's just odd practice, imo.
html is a markup language, php is something completely different. i'm gonna miss that segregation beteen the two
html is a markup language, php is something completely different. i'm gonna miss that segregation beteen the two
Another three hours later, heh. I've never used ASP before, so I've no idea how it works. If it's anything like Perl/CGI, which is what I started out with, where you generate HTML using the language's equivalent of the print function, then I really do appreciate PHP's embedded nature. The separation of presentation from logic is very important, I agree. With PHP, you've got the flexibility to choose to what degree you perform this separation. The ability to easily insert small snippets of code inline is a godsend. In my own code, I keep 99% of the programming separate from the markup and insert it where I need to using includes or classes.
QUOTE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 STRICT//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml11-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php echo $site['lang'] ?>">
<head>
<title><?php echo $title ?></title>
</head>
<body>
</body>
</html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml11-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php echo $site['lang'] ?>">
<head>
<title><?php echo $title ?></title>
</head>
<body>
</body>
</html>
The variables embedded in this example might be set by a function or class that either generates or includes the surrounding HTML code. For example, a function to display the pages heading might be similar to the following.
CODE
function print_heading($lang,$title) {
include 'page_heading.php';
}
include 'page_heading.php';
}
This is a pretty crappy example, but I hope it demonstrates at least to some degree how it's perfectly possible to separate presentation from logic. I'm going to cut myself some slack either way since I've just woken up from a grand four hours of sleep.
Edit: As far as maintainability goes, here's a more concrete example of how easy it is to update an entire site with PHP just by editing a line or two in an include file.
CODE
Logic (includes.php):
function print_menu {
$menu = array ( 'Home' => 'home',
'Titties' => 'titties',
'Gadgets' => 'gadgets',
'Contact Us' => 'contact',
);
foreach ( $menu as $page => $ident ) {
$menu .= "<li><a href=\"index.php?act=$ident\">$page</a></li>\n";
}
return $menu;
}
/* ---------------------------------------------------------------------------------------------------------- */
Presentation (index.php):
<?php include includes.php ?>
<html>
<head>
</head>
<body>
<ul id="mainnav">
<?php print_menu() ?>
</ul>
----- CONTENT HERE ------
</body>
</html>
function print_menu {
$menu = array ( 'Home' => 'home',
'Titties' => 'titties',
'Gadgets' => 'gadgets',
'Contact Us' => 'contact',
);
foreach ( $menu as $page => $ident ) {
$menu .= "<li><a href=\"index.php?act=$ident\">$page</a></li>\n";
}
return $menu;
}
/* ---------------------------------------------------------------------------------------------------------- */
Presentation (index.php):
<?php include includes.php ?>
<html>
<head>
</head>
<body>
<ul id="mainnav">
<?php print_menu() ?>
</ul>
----- CONTENT HERE ------
</body>
</html>
Here you see the ability for a site to update it's menu simply by modifying the array in the file includes.php. This method allows you to be flexible in the maintenance of your site while leaving the styling of the menu completely separate from the PHP coding. An alternative would be to allow you to pass the menu items to the print_menu function inside of the HTML code.
CODE
In the HTML:
<body>
<?php print_menu('Home' => 'home', 'Titties' => 'titties...etc) ?>
</body>
In the PHP:
function print_menu($links) {
// Function is identical, except that the array is already defined by the $links argument
}
<body>
<?php print_menu('Home' => 'home', 'Titties' => 'titties...etc) ?>
</body>
In the PHP:
function print_menu($links) {
// Function is identical, except that the array is already defined by the $links argument
}