ページのテンプレートでデータを取得するために機能する汎用関数を取得したいと思います。プロパティが設定されていない場合は、親または親の親などから取得します。ジェネリックとは、db、HasOne、HasMany、ManyMany などの関係から独立していることを意味します。ManyMany に対してこれを持っているが、それがオブジェクト、HasManyList、ManyManyList、または値であるかどうかを検出したいとします。このようなものは組み込まれていますか、それともどうしますか?
function ManyManyUpUntilHit($ComponentName){
$Component = $this->getManyManyComponents($ComponentName);
if($Component && $Component->exists())
return $Component;
$Parent = $this->Parent();
if(is_object($Parent) && $Parent->ID != 0){
return $Parent->ManyManyUpUntilHit($ComponentName);
} else {
return null;
}
}
テンプレート内:
$ManyManyUpUntilHit(Teaser)