2
echo $form->input(
    'country_id',
    array(
        'type' => 'select', 
        'label' => __('Country *', true), 
        'empty' => 'Select' , 
        'order' => array('countries.name ASC')
    )
);

国家/地区列表未按升序显示。请任何人帮助我找出错误或按升序显示国家/地区列表的好方法。

4

2 回答 2

6

您需要添加order到您的find查询:

$countries = $this->Country->find('list', array(
    'fields' => array('Country.id', 'Country.name'), 
    'order' => array('Country.name' => 'ASC')
))
于 2013-01-22T16:37:12.137 回答
0

对于 cakephp 3.*,您可以使用此代码;

$countries = $this->Country
           ->find('list',
           [
               'keyField' => 'Country.id',
               'valueField' => 'Country.name',
               'order' => array('Country.name' => 'ASC')
           ])
           ->toArray();
于 2018-12-24T09:42:42.990 回答