php - Variable as Array Key - Yii Dropdown Selected -


i using yii , have dropdown using following example:

$form->dropdownlist($model,'sex',array('1'=>'men','2'=>'women'), array('options' => array('2'=>array('selected'=>true)))); 

here able choose option selected. if set 2 shown in example above selected option women expected. not able statically set selected option need use variable. have $selectedid equal 2, when doing example:

array('options' => array("$selectedid"=>array('selected'=>true)))); 

or doing this:

array('options' => array($selectedid=>array('selected'=>true)))); 

i getting no errors, dropdown not have expected selected option. possible use variable when defining array key?

update

true string:

chtml::dropdownlist('package','',chtml::listdata(services::model()->findall(array('condition'=>'is_internet = 1','params'=>array())), 'id', 'name'),array('id'=>'package')) 

you can set setting second parameter:

chtml::dropdownlist('package',$selectedid,chtml::listdata(services::model()->findall(array('condition'=>'is_internet = 1','params'=>array())), 'id', 'name'),array('id'=>'package')) 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -