archi
(Kazineel)
December 16, 2009, 9:17pm
1
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
mbi
(mbi)
December 16, 2009, 9:51pm
2
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
colt
(Linija)
December 26, 2009, 10:34am
3
Maybe some code example? 10x
mbi
(mbi)
December 26, 2009, 10:58am
4
echo CHtml::activeDropDownList($model,'u_id', array_merge(array('0' => 'Choose name'), CHtml::listData(CActiveRecord::model('User')->findAll(),'id','lName')));
teguheko
(Teguheko)
January 10, 2010, 4:36pm
6
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 ?
mbi:
echo CHtml::activeDropDownList($model,'u_id', array_merge(array('0' => 'Choose name'), CHtml::listData(CActiveRecord::model('User')->findAll(),'id','lName')));
teguheko
(Teguheko)
January 10, 2010, 4:45pm
7
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'))
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 ?
colt
(Linija)
January 11, 2010, 10:05pm
8
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!
umutau
(Umutau)
December 20, 2010, 2:01am
10
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'));
shailesh
(Shailesh Makwana990)
May 20, 2011, 1:06pm
11
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()
{
$trips = ConfigModel::model()->findAll();
$arr = array();
foreach($trips as $t)
{
$arr =array_merge($arr,explode("|",$t->dbServerName));
}
return $arr;
}