gpt4 book ai didi

php - 我如何在 SilverStripe 3.1 中按字母顺序排序(但大写字母不是小写字母之前的一组)?

转载 作者:可可西里 更新时间:2023-11-01 07:44:13 26 4
gpt4 key购买 nike

在 SilverStripe 3.1 中,我可以通过执行以下操作获得 Children 的排序列表:

$this->Children()->sort('Title', 'ASC');

但是当我这样做时,大写字母(作为一个组)排在小写字母(作为一个组)之前;因此“D”出现在“a”之前:

Aadb
Bdbdd
Cdbd
Dbddb
aeb

但我想要这样的排序顺序:

Aadb
aeb
Bdbdd
Cdbd
Dbddb

我如何在 SilverStripe 中执行此操作?

编辑

我找到了一个类似的 question Willr 说:

Strange! I would have thought it would be case insensitive. You could simply export the array list as an array ($list->map()) then write your own sort logic.

有人知道怎么做吗?

我尝试了以下方法,但没有返回任何结果:

function SortedChildren(){
$sortChildren = $this->Children()->map();
natcasesort($sortChildren);
return $sortChildren;
}

最佳答案

好吧,我终于想出了如何编写和使用我自己的排序逻辑:

function SortChildren() {

$_list = $this->Children()->map("URLSegment", "Title");
natcasesort($_list);

$sortedChildren = new ArrayList();
foreach($_list as $key => $value ){
$fields = new ArrayData(array('ChildURL' => $key, 'Title' => $value));
$sortedChildren->push($fields);
}
return $sortedChildren;

}

然后在模板中使用:

<% loop SortChildren %>
<div class="child"><a href="$ChildURL">$Title</a></div>
<% end_loop %>

关于php - 我如何在 SilverStripe 3.1 中按字母顺序排序(但大写字母不是小写字母之前的一组)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32347188/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com