I try to do class tree where each class in tree check own directory for template and use it, but when I call function in inherited class then called parent. How can i do it ?
My code in example below output:
D
C
b/1.phtml
but i need to d/1.phtml
<?php
class A {
private $templates_dir = 'a';
}
class B extends A {
private $templates_dir = 'b';
public function templates_dir()
{
return $this->templates_dir;
}
public function check_template($tpl)
{
$dir = $this->templates_dir();
$file = $dir. '/'. $tpl;
echo (get_class($this)). "\r\n";
echo (get_parent_class($this)). "\r\n";
echo $file . "\r\n";
// idea - if (!file_exists($file)) return parent::check_template($file);
// method call each class while template will be found
// how do it?
}
}
class C extends B {
private $templates_dir = 'c';
}
class D extends C {
private $templates_dir = 'd';
}
$obj = new D();
$obj->check_template('1.phtml');