I am new to Yii framework.
I have a form with three fields. I need one of those be a select drop down element that its data comes from previously added data which are in mysql table.
How can I do it ?
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.
If you have a model set up for the table that contains the data you want to use in your dropdown list you can use the
CHtml::dropDownList()method the render a dropdown list, andCHtml::listData()to render that model into items for the list, for example;I use Gii a lot, which uses CActiveForm widget to display forms, if your form uses CActiveForm too you could render your dropdown something like;
Note that CActiveForm uses
CHtml::activeDropDownList()rather thanCHtml::dropDownList()that I used in my first example, hence the slight difference in syntax between my two examples.