activeDropDownList

Hello,

I want to populate activeDropDownList but first list will show 0(this is manual) and then record from database. Is that possible?

Here is my code

<?php echo CHtml::activeDropDownList($model,‘u_id’, CHtml::listData(CActiveRecord::model(‘User’)->findAll(),‘id’,‘lName’)); ?>

like this

0

abc

def

ge

ab

you have to merge your data with Model-Data - array_merge is your friend

Maybe some code example? 10x




echo CHtml::activeDropDownList($model,'u_id', array_merge(array('0' => 'Choose name'), CHtml::listData(CActiveRecord::model('User')->findAll(),'id','lName')));



Fast answer. Thanks

Yii community rocks!

Cheers!

Hi,

I tried to use activeDropDownList, but I stumbled with the $model variable.

The error is : Undefined variable: model

Which value should I assign to the variable $model ?

I found the solution by myself :)

the model should be the name of the model who has the attribute that the value of the dropdownlist will be assigned to. For example for Visa and visa type:


$criteria = new CDbCriteria;

$criteria->order = 'category, status_residence';

$criteria->select = "id, category, status_residence";

$visaArray = Visa_Type::model()->findAll($criteria);

$model =Visa::model();

echo CHtml::activeDropDownList($model, 'visa_type_id', CHtml::listData($visaArray, 'id', 'status_residence', 'category'))

Yii community has a good habit to share each other problems and solutions, even found by authors themselves!

Greets!

Thank you very much!!!

Instead of merging and calling database from view probably better to use ‘empty’ property also get list from model-controller




CHtml::activeDropDownList($model,'u_id',$list,array('empty'=>'Choose name'));



CActiveRecord::model(‘User’)->findAll()

returns U group Of Array

Have to Define Inside One Function and Do in single Array

Me have done Thse To remove

Try Below Code

public function getserverList()

{


	&#036;trips = ConfigModel::model()-&gt;findAll();


	&#036;arr = array();





	foreach(&#036;trips as &#036;t)


	{


		    &#036;arr =array_merge(&#036;arr,explode(&quot;|&quot;,&#036;t-&gt;dbServerName));


	}	





	return &#036;arr;





  


}