如何访问 $Children 页面控制器功能?
How to access $Children page controller functions?
我在 CMS 中使用 SilverStripe 框架,我 运行 在访问当前页面中的子页面功能时遇到了麻烦。
假设我们有 CataloguePage
种页面类型,并且它有很多 ProductPage
种页面类型。在 ProductPage
中有一个函数。我想在 CataloguePage
视图中访问此功能。
我该怎么做?
这实际上不能满足我的要求,但我认为我已经非常接近解决方案了:
<% loop $Children %>
$MyChildrenPageFunction
<% end_loop %>
有什么帮助吗?
嗯,所有修改子 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
我在 CMS 中使用 SilverStripe 框架,我 运行 在访问当前页面中的子页面功能时遇到了麻烦。
假设我们有 CataloguePage
种页面类型,并且它有很多 ProductPage
种页面类型。在 ProductPage
中有一个函数。我想在 CataloguePage
视图中访问此功能。
我该怎么做?
这实际上不能满足我的要求,但我认为我已经非常接近解决方案了:
<% loop $Children %>
$MyChildrenPageFunction
<% end_loop %>
有什么帮助吗?
嗯,所有修改子 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