Automatic translation of multioptions in Zend_Form breaks sortorder

664 Views Asked by At

I have the following issue. I create a Zend_Select element and add multioptions in an array. Zend automatically translates the options, after which my multioptions are sorted incorrectly.

Right now, my only option seems to be:

$element = $this->createElement("select", "name");
$element->setMultiOptions($myArray);
$options = $element->getMultiOptions(); // OPTIONS HAVE BEEN TRANSLATED HERE
asort($options);
$element->setMultiOptions($options);

Anyone know a better way to do this?

1

There are 1 best solutions below

0
On

I usually always translate the options before sending them to the element :

$myArray = ...; // key/value array with values translated
asort($myArray);
$element->setMultiOptions($myArray);

But your solution looks just as good from my point of view.