ツリー内の各クラスが独自のディレクトリでテンプレートをチェックして使用するクラスツリーを作成しようとしましたが、継承されたクラスで関数を呼び出してからparentと呼ばれました。どうすればいいですか?PHP:継承に関する問題
マイ出力以下の例のコード:
D
C
B/1.phtml
私は必要に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');
あなたは痛みの世界に入っているすべてのそれらのサブクラスで - 以下
はコードです。 – Federkun