php - How to make a dropDownList in Yii? -
i have 2 attributes in model jobs
, tag
, category
, want create dropdownlist display value of tag
have category
equal 'salary', here code:
$s= chtml::listdata($model2, 'salary', 'tag'); echo chtml::dropdownlist('salary', 'salary', $s);
my db:
tag / category
1 / val1
2 / val1
a / val2
1000 / salary
2000 / salary
but got dropdownlist contains lastly value have these conditions. wrong in code?
there 2 reasons why can 1 results, firstly number of results in $model2
affects results, check if using findall
homecoming rows matching status , not find
, findbypk
homecoming 1 value,
secondly sec attribute of listdata should value field 'salary' not attribute of model, has valuefield(see this).
it remain same if assigned salary
- constant value alternative elements, meaning array overwritten each reach leaving array of 1 element containing lastly value.
you should 'tag_id'/'id' or sort of primary key model or tag value( assuming unique) identify tag by
$model2 = mymodel::model()->findall("category = salary"); $s= chtml::listdata($model2, 'tag', 'tag'); echo chtml::dropdownlist('salary', 'salary', $s,array('empty'=>'--select--'));
php yii yii-chtml
No comments:
Post a Comment