how can i do this
$arr[]='a';
$arr[]='b';
$arr[]='c';
CHtml::listData($arr, '?', '?')
i want get
how can i do this
$arr[]='a';
$arr[]='b';
$arr[]='c';
CHtml::listData($arr, '?', '?')
i want get
i think you need a dropDownList
http://www.yiiframework.com/doc/api/1.1/CHtml#dropDownList-detail
$arr[‘a’]=‘a’;
$arr[‘b’]=‘b’;
$arr[‘c’]=‘c’;
CHtml::dropDownList("Goods[fileName]", "", $arr, array ( ))
i know about dropDownList, also i knew about $arr[‘a’]=‘a’;
lol do you think i don’t know about dropDownList?
i want solution without duplicate keys
You don’t have to use CListData if you have already an array ready.
ClistData is an helper for transform an array of models in an array of key-value pairs for dropDownList.
If you want a dropdownlist you can simply do as said ahmed, if you are working with active records use, for example:
CHtml::dropDownList("Goods[fileName]", "", CHtml::listData($arrayOfModels, 'primaryKey','primaryKey' )))
but i don’t work with array of models, i work with one dimention array. and i don’t want to make it two dimention with duplicate keys
so i need some solution to do it
I didn’t get it…
CHtml.activeDropDownList() 3rd argument is an array of pairs value=>display, so if you want to generate a list using this method you have to pass the following array:
$arr['a']='a';
$arr['b']='b';
$arr['c']='c';
But if you just don’t like this syntax, you can try the following:
$data = array('a', 'b', 'c');
CHtml::activeDropDownList($model, 'fileName', array_combine(array_values($data), $data));
oh these useful php functions
ok, so i see there no nice solution for this
so will make array with duplicate keys $arr[‘a’]=‘a’;
i have array
array('0'=>'new','1'=>'established')
so i want it in
CHtml::listData();
so i can i achieve this is there any way. Thank you
Don’t judge about existence of a thing by absence of answers regarding this thing
Here is a solution for you (for PHP 5.3+):
$arr[]='a';
$arr[]='b';
$arr[]='c';
CHtml::listData($arr, function($model){ return $model; }, function($model){ return $model; });
Your array is already in the suitable form for
dropDownList
or
checkBoxList
.
Thank you, this is what i need