【问题标题】:How can I access the children of a Silverstripe Page in the Page's controller?如何在页面控制器中访问 Silverstripe 页面的子级?
【发布时间】:2014-04-23 10:28:48
【问题描述】:

我正在与 Silverstripe 合作,并试图找出一个页面有多少个孩子。我怎样才能最好地从 Page_Controller 类中做到这一点?

我要做的是根据它必须显示的子元素数量来计算模板中导航 DIV 的高度。所以我正在寻找一个返回 [# of Children] * [Height per Child] 的函数。

谁能告诉我如何才能让 # of children 进入 Page 对象?

【问题讨论】:

    标签: php silverstripe


    【解决方案1】:

    ArrayList 有一个 count() 函数,它将返回列表中的项目数。

    您可以在您的页面Children列表中调用count()

    $this->Children()->count();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-27
      相关资源
      最近更新 更多