【问题标题】:Merge two page type in SilverStripe在 SilverStripe 中合并两个页面类型
【发布时间】:2015-07-14 08:50:12
【问题描述】:
$page1 = PageType1::get();
$page2 = PageType2::get();

有没有办法从两种页面类型的组合中获取最新的 5 篇文章。 接受任何帮助。

【问题讨论】:

    标签: silverstripe


    【解决方案1】:

    假设 PageType1PageType2 都是 Page 类的孩子,你可以这样做:

    $myPages = Page::get()->filter(['ClassName' => ['PageType1', 'PageType2']]);
    

    或这两种页面类型的任何其他父类。

    您可以按创建日期(保存在 SiteTree 表中)和限制进行排序,例如

    $sortedAndLimited = $myPages->sort('Created')->limit(5);
    

    缺点:您无法轻松搜索、过滤或排序未与父类 Page 共享的单个字段,为此您需要手动进行连接。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-27
      • 2011-05-04
      • 1970-01-01
      • 1970-01-01
      • 2013-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多