How To Use Loop In Dropdownbox

I have a _form.php file then I want to create a dropdownlist want to use for loop




<?php

    echo $form->dropDownListRow($model, 'Time', array($this->loop()),array('class'=>'input-small'));

?>



Controller file have the function loop




public function loop()

{

     $colors = array(0,1,2,3,4,5,6,7,8,9);

     foreach ($colors as $value)

     {

        echo "$value <br>";

     }

}



in dropDownListRow the array(…) expects array items

so,


public function loop()

{

     $colors = array(0,1,2,3,4,5,6,7,8,9);

     $c =array();

     foreach ($colors as $value)

     {

        $c[] = $value . '<br/>' ; //why you want to use <br> ?

     }

     return $c;

}

and


<?php

    echo $form->dropDownListRow($model, 'Time', $this->loop(),array('class'=>'input-small'));

?>

Thank you very much.

Welcome!

Could you please tell us why you want to use <br> ?

May be other members want to know it :)

use that to new line, but now I not use <br>. :)

How to get select value in controller? Thx.

to get selected value in controller?

you got it in post/request array when user submit the form, ie




 echo $_POST['Model_class']['Time'];


 //or in a yii way

 $model = new Model_class;

 $model->attributes = $_POST['Model_class'];

 echo $model->Time;



to set a value? set it before rendering the view




 $model = new Model_class;

 $model->Time = 3;


 $this->render('viewname', array('model'=>$model));