Referring to patrikG's link about Registry patterns and Singletons: I had been reading about those, but the text relied heavily on the new OOP features PHP5 provided that I dismissed them as impossible to implement in PHP4... this might be the solution. The main point is that while I was learning to use Smarty, I found myself having to constantly do this:
Code: Select all
$smarty->assign('page_name','The Observer');
$smarty->assign('subtitle','Always Always!');
//...
Then I did this:
Code: Select all
$headers['page_title'] = 'The Observer';
$headers['subtitle'] = 'Always Always';
$smarty->assign('headers',$headers);
But the naming conventions were terribly ad hoc, so finally, I decided:
Code: Select all
//Only use $VAR, $ARRAY, $PRE, $IS
$VAR['page_title'] = 'The Observer';
$VAR['subtitle'] = 'Always Always';
$IS['display_subtitle'] = false;
$smarty->assign('var',$VAR);
$smarty->assign('is',$IS);
So, according to the link, what you're proposing is I do this:
Code: Select all
$registry = new Registry;
$registry->is['display_subtitle'] = false;
//or...
//(note how the array key is added, for a type of 'hierarchy'
$registry->assign('is','display_subtitle',false);
if ($registry->is['display_subtitle']) {
//parse subtitle
}
$smarty->assign('base',$registry); //pass the registry in
Or basically, make my own registry (don't use smarty) for storing variables, and then pass it to smarty?
-_-" My code is still way too procedural.