I’ve been working for the past 2 hours to try to generate a simple drop down list in my view.
I am a beginner and not capable to get things working based on the document here. I am pretty lost about the data type and coudln’t figure out why we need listData() to generate data for dropDownList(). Learning how to use dropDownList() is hard enough for me.
Please help me provide an example, and assume I know nothing.
// Normal dropdownlist
<?php echo $form->dropDownList($model, 'field_name', array(1=>'test1', 2=>'test2'));?>
// List data need when populating dropdown from database values
<?php echo $form->dropDownList($model,'node_types_id', CHtml::listData(NodeTypes::model()->findAll(array('order' => 'name')),'id','name'));?>
I assume based on the syntax you are using that you are using CActiveForm, the second parameter needs to be a valid attribute on your Model, so this is why you are getting an error. The third parameter needs to be an array.