Silverstripe 3 过滤器 ArrayList
Silverstripe 3 filter ArrayList
我们如何在 Silverstripe 3 中过滤 ArrayList?
其中 getVideosfromCategories() returns 一个合并的 ArrayList
我需要类似的东西:
$this->getVideosfromCategories()->filter('ID:LessThan', $id)->sort(array('ID' => 'DESC'))->first()
这些过滤器 (filter('ID:LessThan', $id)) 仅适用于 DataList ?
如何过滤我的 ArrayList?
these Filters (filter('ID:LessThan', $id)) only work with DataList ?
是的,没错,搜索过滤器修饰符仅适用于 DataList
个实例。
(https://docs.silverstripe.org/en/3/developer_guides/model/searchfilters/) 有趣的是文档没有提到这一点,我认为应该更新一下。
(我给它开了个PRhttps://github.com/silverstripe/silverstripe-framework/pull/9363)
但是您可以修改当前代码以改为按 ID 数组进行过滤,如下所示:
$idsWeWant = [];
if ($id > 0) {
$idsWeWant = range(0, $id - 1); // "$id - 1" because you had "LessThan" modifier.
}
$this->getVideosfromCategories()
->filter('ID', $idsWeWant)
->sort(array('ID' => 'DESC'))
->first();
我们如何在 Silverstripe 3 中过滤 ArrayList?
其中 getVideosfromCategories() returns 一个合并的 ArrayList
我需要类似的东西:
$this->getVideosfromCategories()->filter('ID:LessThan', $id)->sort(array('ID' => 'DESC'))->first()
这些过滤器 (filter('ID:LessThan', $id)) 仅适用于 DataList ?
如何过滤我的 ArrayList?
these Filters (filter('ID:LessThan', $id)) only work with DataList ?
是的,没错,搜索过滤器修饰符仅适用于 DataList
个实例。
(https://docs.silverstripe.org/en/3/developer_guides/model/searchfilters/) 有趣的是文档没有提到这一点,我认为应该更新一下。
(我给它开了个PRhttps://github.com/silverstripe/silverstripe-framework/pull/9363)
但是您可以修改当前代码以改为按 ID 数组进行过滤,如下所示:
$idsWeWant = [];
if ($id > 0) {
$idsWeWant = range(0, $id - 1); // "$id - 1" because you had "LessThan" modifier.
}
$this->getVideosfromCategories()
->filter('ID', $idsWeWant)
->sort(array('ID' => 'DESC'))
->first();