Hay I am using a static drop down in my site
<?php echo $form->dropDownList($model,'status',array("1"=>"Active","0"=>"InActive")); ?>
i want that when i retrieve status in CDetailView it shows name active instead of value . Please tell me how can i do like this? thanks in advance.
mmbalaa
(Mmbalasundaram)
March 1, 2013, 8:17am
2
Do you want this ?
<?php echo $form->dropDownList($model,'status',array("1"=>"Active","0"=>"InActive"),array('empty'=>'Select Value')); ?>
Hay I am using a static drop down in my site
<?php echo $form->dropDownList($model,'status',array("1"=>"Active","0"=>"InActive")); ?>
i want that when i retrieve status in CDetailView it shows name active instead of value . Please tell me how can i do like this? thanks in advance.
What is saved in your database, the value (0 or 1) or the description (“Active” or “InActive”)? If values are saved, then I don’t think you need to do anything in CDetailView aside from including it in the ‘attributes’. If you’re saving the description, then you might have to create a function to process what should be displayed, then call it from the CDetailView.
Do you want this ?
<?php echo $form->dropDownList($model,'status',array("1"=>"Active","0"=>"InActive"),array('empty'=>'Select Value')); ?>
no but thanks for this editing too.
macinville:
What is saved in your database, the value (0 or 1) or the description (“Active” or “InActive”)? If values are saved, then I don’t think you need to do anything in CDetailView aside from including it in the ‘attributes’. If you’re saving the description, then you might have to create a function to process what should be displayed, then call it from the CDetailView.
thanks dear you understand my problem but please write a code snippet like in dynamic dropdown list we do
array (
'name'=>'country',
'value'=>$model->country->country_id,
),
In your Status model, add a static function like this one
public static function getStatus($status){
return $status=="Active" ? 1:0;
}
And in your CDetailView, make it look like this:
...
'attributes'=>array(
...//other fields
array(
'name'=>'status',
'value'=>Status::getStatus($model->status)
)
...
),
...
Something like that. I do not have the opportunity to actually test this code, but I think this will work for you.
mjkulet
(Mjkulet)
March 2, 2013, 12:54am
9
Thanks mate, I needed something like this badly today.
+1 for helping me out