This is a follow up from yesterday's scope question.
stackoverflow.com/questions/3301377/class-scope-question-in-php
Today I want to share the "$template_instance" variable with a child class. How is this accomplished?
require_once("/classes/Conf.php");
require_once("/classes/Application.php");
class index extends Application
{
private $template_instance;
// Dependency injection
public function __construct(Smarty $template_instance)
{
$this->template_instance = $template_instance;
}
function ShowPage()
{
// now let us try to move this to another class
// $this->template_instance->assign('name', 'Ned');
// $this->template_instance->display('index.tpl');
}
}
$template_instance = new Smarty();
$index_instance = new Index($template_instance);
//$index_instance->showPage();
$printpage_instance = new printpage();
$printpage_instance->printSomething();
------------------------------------------------------------------
class printpage
{
public function __construct()
{
}
public function printSomething()
{
// now let us try to move this to another class
$this->template_instance->assign('name', 'Ned');
$this->template_instance->display('index.tpl');
}
}