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

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

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

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

Aadb
Bdbdd
Cdbd
Dbddb
aeb

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

Aadb
aeb
Bdbdd
Cdbd
Dbddb

我怎么能在SilverStripe中做到这一点?

编辑

我找到了类似的question,威尔说:

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 %>

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...