[Form] Moved the access to templating helpers out of the choice loop for performance reasons (PHP +100ms)

This commit is contained in:
Bernhard Schussek 2012-07-16 18:03:21 +02:00
parent 0ef9acb479
commit 5dc3c39fd2
1 changed files with 5 additions and 3 deletions

View File

@ -1,9 +1,11 @@
<?php $translatorHelper = $view['translator']; // outside of the loop for performance reasons! ?>
<?php $formHelper = $view['form']; ?>
<?php foreach ($choices as $index => $choice): ?>
<?php if (is_array($choice)): ?>
<optgroup label="<?php echo $view->escape($view['translator']->trans($index, array(), $translation_domain)) ?>">
<?php echo $view['form']->block('choice_widget_options', array('choices' => $choice)) ?>
<optgroup label="<?php echo $view->escape($translatorHelper->trans($index, array(), $translation_domain)) ?>">
<?php echo $formHelper->block('choice_widget_options', array('choices' => $choice)) ?>
</optgroup>
<?php else: ?>
<option value="<?php echo $view->escape($choice->value) ?>"<?php if ($choice->isSelected($value)): ?> selected="selected"<?php endif?>><?php echo $view->escape($view['translator']->trans($choice->label, array(), $translation_domain)) ?></option>
<option value="<?php echo $view->escape($choice->value) ?>"<?php if ($choice->isSelected($value)): ?> selected="selected"<?php endif?>><?php echo $view->escape($translatorHelper->trans($choice->label, array(), $translation_domain)) ?></option>
<?php endif ?>
<?php endforeach ?>