Yii Static Drop Down List

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.

Do you want this ?


		

<?php echo $form->dropDownList($model,'status',array("1"=>"Active","0"=>"InActive"),array('empty'=>'Select Value')); ?>



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.

no but thanks for this editing too.

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.

thanks this work for me

Glad it worked for you. :)

Thanks mate, I needed something like this badly today.

+1 for helping me out :)