0
$getCities = $this->requestAction('objekts/getCities');

This returns me a list with ids and names of cities in alphabetical order. When I debug $getCities I can see the alphabetical order.

This is the way how I select the data:

 $results = $this->find('list', array(
            'conditions' => array($and, $andZone),
            'fields' => 'REG_ID, REG_NAME',
            'group' => 'REG_ID',
            'order' => array('REG_NAME ASC')
        ));

Again, the debug data is in alphabetical order.

But!

echo $this->Form->input('city', array('label' => __('Nach Ort suchen'), 'empty' => __('Bitte wählen'), 'options' => $getCities, 'id' => 'city', 'class' => 'styled-select'));

This is changing the order to it's id's and does not keep my alphabetical order on the city names.

Is there anything I can add to the $this->Form->input to set my order to names instead of ids?

Please advice!

Thanks!!

edit:

this is the debug array

'{"4":"Alar\u00f3","67":"Algaida","99":"Alqueria Blanca","5":"Andratx","6":"Art\u00e1","8":"Bendinat","105":"Biniali","9":"Binissalem","70":"Bunyola",.....

this is the html output

<select id="city" class="styled-select" name="data[Objekt][city]">
<option value="">Bitte wählen</option>
<option value="4">Alaró</option>
<option value="5">Andratx</option>
<option value="6">Artá</option>
....
<option value="67">Algaida</option>
...
<option value="99">Alqueria Blanca</option>
....
user1555112
  • 1,897
  • 6
  • 24
  • 43
  • You can change in your function getCities to order using name. – Abhishek Sep 22 '14 at 11:37
  • I do that already! As I said in my posting - that the debug of that request is already in alphabetical order. But the output is changing the order to ids not names! – user1555112 Sep 22 '14 at 12:18
  • Could you show your array sample? – marian0 Sep 22 '14 at 13:06
  • array( (int) 4 => 'Alaró', (int) 67 => 'Algaida', (int) 99 => 'Alqueria Blanca', (int) 5 => 'Andratx', (int) 6 => 'Artá', (int) 8 => 'Bendinat', In case that is easier to read... – user1555112 Sep 22 '14 at 13:31
  • Where does the JSON data stem from? Is it that you just dumped the data using `json_encode()` for debugging purposes? Have you tried the latest CakePHP version, because it works just fine over here, the form helper doesn't change the order? – ndm Sep 22 '14 at 14:09
  • Nothing is changeing when I use find('all')... the problem remains. I am using Cake 2.5.1 – user1555112 Sep 22 '14 at 14:15
  • I have to say that in my jquery file I have this line to catch the data: $.getJSON('/objekts/getCities/false/'+searchZone+'/1/', function(data){console.log(data); The ouptput of the console is sorted by id's - not by names. So it seems right, that json_encode is changing the order??? – user1555112 Sep 22 '14 at 14:21
  • http://stackoverflow.com/questions/21216391/prevent-json-encode-associative-array-sorting and http://stackoverflow.com/questions/5020699/how-do-you-stop-chrome-and-opera-sorting-json-objects-by-index-asc Here are some more infos about this behavior... – user1555112 Sep 22 '14 at 14:25
  • So basically the code you have shown here has nothing to do with what you are actually doing? I mean, where is this JavaScript being executed? Are you inserting the select values via JavaScript?... It's always advised to show _all_ the _exact_ code _involved_ in order to receive proper advises for fixing a problem. – ndm Sep 22 '14 at 15:13

0 Answers0