我在CMS中使用 SilverStripe 框架,在当前页面中访问子页面功能时遇到了麻烦。
假设我们有CataloguePage
页面类型,并且它有很多ProductPage
页面类型。在ProductPage
中有一个函数。我想在CataloguePage
视图中访问此功能。
我该怎么做?
这实际上不能做我想要的,但我认为我非常接近解决方案:
<% loop $Children %>
$MyChildrenPageFunction
<% end_loop %>
请帮忙吗?
答案 0 :(得分:3)
那么,修改子DataObject的所有方法都应该在DataObject / Page本身,而不是在控制器中。因此最简单的方法是将方法移动到DataObject或Page,方法是复制它或者通过创建DataExtension并将其应用于子页面类型。
class MyStuff extends DataExtension {
public method doSomething() {
return 'I did something';
}
}
并在 mysite / _config / config.yml 中:
ChildPageType: #classname of the page type you want to decorate
extensions:
- MyStuff #class name of the extension you want to apply