How to select a column of data from table with WHERE closure and list as combo-box in yii?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Have a look at the CHtml methods dropDownList() and activeDropDownList().
You can set the data you insert into the dropdownlist to be the results from an active record query, for example;
The above command would select all the results from the
myModelmodel wheremyField = 1(using their ‘id’ as the value and their ‘name’ as the displayed text) and insert them into a dropdownlist with name ‘myDropdown’ and the initial selected value would be 1.If you’re using this in a form, for example created by gii, then you can use the $form to create the dropdown. This actually uses activeDropDownList(), so the syntax is a little different, here’s an example:
the bit that’s actually populating the dropdownlist with the data from the active record query is the CHtml::listData() method which is taking a result set from the active record query and formatting it into an array that will be accepted into the
$dataparam in dropDownList() or activeDropDownList().