Yii Framework Forum: Yii Static Drop Down List - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii Static Drop Down List How to show dropdown list name instead of value in cDetailView Rate Topic: ***-- 1 Votes

#1 User is offline   zohaib 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 27-February 13

Posted 01 March 2013 - 03:04 AM

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.
0

#2 User is offline   mbala 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 144
  • Joined: 21-July 12
  • Location:Chennai, Tamilnadu, India

Posted 01 March 2013 - 03:17 AM

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

0

#3 User is offline   macinville 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 268
  • Joined: 25-October 10
  • Location:Marikina City, Philippines

Posted 01 March 2013 - 03:35 AM

View Postzohaib, on 01 March 2013 - 03:04 AM, said:

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.
Tell your tail.
Don't be shy to upvote a post if it was able to help you
0

#4 User is offline   zohaib 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 27-February 13

Posted 01 March 2013 - 08:32 AM

View Postmbala, on 01 March 2013 - 03:17 AM, said:

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.
0

#5 User is offline   zohaib 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 27-February 13

Posted 01 March 2013 - 08:37 AM

View Postmacinville, on 01 March 2013 - 03:35 AM, said:

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,
		),

0

#6 User is offline   macinville 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 268
  • Joined: 25-October 10
  • Location:Marikina City, Philippines

Posted 01 March 2013 - 10:41 AM

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.
Tell your tail.
Don't be shy to upvote a post if it was able to help you
2

#7 User is offline   zohaib 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 27-February 13

Posted 01 March 2013 - 12:21 PM

View Postmacinville, on 01 March 2013 - 10:41 AM, said:

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
0

#8 User is offline   macinville 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 268
  • Joined: 25-October 10
  • Location:Marikina City, Philippines

Posted 01 March 2013 - 07:40 PM

Glad it worked for you. :)
Tell your tail.
Don't be shy to upvote a post if it was able to help you
0

#9 User is offline   mjkulet 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 82
  • Joined: 03-November 10

Posted 01 March 2013 - 07:54 PM

Thanks mate, I needed something like this badly today.

+1 for helping me out :)
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users