Stumbled on a really awesome overview of object oriented programming for PHP 5. If you're looking to get out of the php 4 mindset, this is a good place to start.
My arch-nemisis is overly complex logic in template.php and page.tpl.php files. It seems to me that when a drupal codebase becomes brittle and unmaintainable, the culprit is usually going to be hundreds of conditional lines of php code in a template file. You've probably seen code like this before:
THEMES/SPAGETTI_MONSTER/TEMPLATE.PHP
<?php
function spagetti_monster_page($content) {
// determine weather the page is a node view, or edit
switch(arg(0)) {
case 'node':
if (is_numeric(arg(1)) && (!arg(2) || arg(2) == 'view')) {
$body_class = 'node_view';
}
else if (arg(1) == 'add' || arg(2) == 'edit') {
$body_class = 'node_compose';
}
// f#ck it, the clients will never look at these pages....
else {
$body_class = 'node_wtf';
}
break;
case 'user':
if (is_numeric(arg(1)) && (!arg(2) || arg(2) == 'view')) {
$body_class = 'user_view';
}
//.... and so on and so on and so on.....
break;
}
}
?>The dangers of this approach are something that cannot be explained: they must be felt first hand.
Switching args in a template.php or page.tpl.php file is like doing drugs (minus the laughs): lots of people have done it, survived, and even learned from it; but its an experience that is best avoided if you can help it. So lets see how to avoid it using static variables. (warning, you'll need to use a module).
Recent comments
39 sec ago
3 days 14 min ago
1 week 1 day ago
1 week 2 days ago
1 week 2 days ago
1 week 5 days ago
1 week 6 days ago
1 week 6 days ago
1 week 6 days ago
3 weeks 2 days ago