Hi, i would like to ask for a help about Chtml::dropdownlist with value from database.
I’m just new in Yii, I dont know how to do it.
thanks
Hi, i would like to ask for a help about Chtml::dropdownlist with value from database.
I’m just new in Yii, I dont know how to do it.
thanks
Hi LostCoder,
What is it that you want to ask help for regarding CHtml::dropDownList? Your statement is kinda vague, and there are lots of possible response to it. Kindly narrow down your concern, or at least ask a straight forward question so we can help you more effectively.
Anyway, here is the class reference for dropDownList.
i would just like to ask for a help to display my list of countries from database to a Chtml::dropdownlist.
// in action
$this->render('action_view', array(
'countries' => Country::model()->findAll(),
));
// in view (if you have no form)
<?php echo CHtml::dropdownlist('select_name', '<selected value>', CHtml::listData($countries, 'id', 'name'));?>
// in view (if you have form defined, e.g. for change user country)
<?php $form = $this->beginWidget('CActiveForm', array(
'id'=>'user-form',
'enableAjaxValidation'=>false,
)); ?>
...
<?php echo $form->dropDownList($user, 'country_id', CHtml::listData($countries, 'id', 'name'));?>
..
// close form tag
<?php $this->endWidget(); ?>
thanks and i tried it but i got "Invalid argument supplied for foreach()" error.
Hi please note that dropdownlist expects an array in the following format:
array(‘1’=>‘one’, ‘2’=>‘two’)
can you please explain how you generate the array that you use in your dropdownlist?