kenjisoul
(Xuyuan8)
1
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>";
}
}
konapaz
(Konapaz)
2
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'));
?>
konapaz
(Konapaz)
4
Welcome!
Could you please tell us why you want to use <br> ?
May be other members want to know it 
kenjisoul
(Xuyuan8)
5
use that to new line, but now I not use <br>. 
kenjisoul
(Xuyuan8)
6
How to get select value in controller? Thx.
dmukadar
(Daudmukadar)
7
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));