Symfony 1.4 display an array in templates

You need to use an array in your template but this array is transform as an object by symfony.

in your actions/actions.class.php

public function executeChoix(sfWebRequest $request)
{
        $this->nom_jour = array('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi' , 'Samedi');
}

in your template template/choixSuccess.php

<?php print_r($nom_jour); ?>

This is what you get :
sfOutputEscaperArrayDecorator Object ( [count:sfOutputEscaperArrayDecorator:private] => 7 [value:protected] => Array ( [0] => Dimanche [1] => Lundi [2] => Mardi [3] => Mercredi [4] => Jeudi [5] => Vendredi [6] => Samedi ) [escapingMethod:protected] => esc_specialchars )

To display a proper array, use

<?php print_r($sf_data->getRaw('nom_jour')); ?>

You get the classic print_r render :
Array ( [0] => Dimanche [1] => Lundi [2] => Mardi [3] => Mercredi [4] => Jeudi [5] => Vendredi [6] => Samedi )

Leave a Reply