PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
class TemplateControl{
function display(){
$page = basename($_SERVER['SCRIPT_FILENAME']);
$page = str_replace('.php','', $page);
$template = $page . '_template.php';
return include('templates/'.$template);
}
}
$template = new TemplateControl();
$a = '1';
$template->display();
I have the above class... that is basically going to be used as a simple wrapper for including php files that I will use as "templates"... If I include the template page directly it will pass the $a variable, however by using the class... it does not. Any idea why that would be?
class TemplateControl{
function display( $vars ){
$page = basename($_SERVER['SCRIPT_FILENAME']);
$page = str_replace('.php','', $page);
extract($vars) ; // look this up on php.net to see what it does
$template = $page . '_template.php';
return include('templates/'.$template);
}
}
$template = new TemplateControl();
$vars['a'] = '1';
$template->display($vars);
Ah nice.. hmm.. I wonder if this is the best way to do it... any suggestions for what I'm trying to accomplish? I'd rather use native php, then use a template system.. but I would still like to try and break apart most of the design logic