如何对“列表”查找器查询进行排序?结果未按定义的顺序显示

问题描述 投票:0回答:2

国家未按升序显示。

$coutryTable = TableRegistry::get('Country');
$getall = $coutryTable
    ->find('list', [
        'keyField' => 'phonecode',
        'valueField' => function ($row) {
            return $row['name'] . ' (+ ' . $row['phonecode'] . ')';
        }
    ])
    ->order([
        'Country.name' => 'ASC'
    ]);
cakephp cakephp-3.x
2个回答
0
投票

尝试分类功能https://www.w3schools.com/php/func_array_asort.asp

$coutryTable = TableRegistry::get('Country');
//pr($coutryTable);die();
$getall = $coutryTable->find('list', ['keyField' => 'phonecode', 'valueField' => function ($row) {
            return $row['name'] . ' (+ ' . $row['phonecode'] . ')';
        }])
->toArray();

asort($getAll);

print_r($getAll);

0
投票

$ coutryTable = TableRegistry :: get('Country');

    $getall = $coutryTable->find('list', ['keyField' => function ($rows) {
        return $rows['name'] . ' (+ ' . $rows['phonecode'] . ')';
    }, 'valueField' => function ($row) {
        return $row['name'] . ' (+ ' . $row['phonecode'] . ')';
    }])->order(['Country.id' => 'ASC']);
© www.soinside.com 2019 - 2024. All rights reserved.