Yii Framework Forum: CDetailView & enum field - Yii Framework Forum

Jump to content

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

CDetailView & enum field Rate Topic: -----

#1 User is offline   bulldoze 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 31-December 11

Posted 17 February 2012 - 10:01 AM

Hello

I have a column in database table where column type is enum - enum('Y', 'N'). I print out table row's using zii.widgets.CDetailView. This prints out Y or N depends on column value, but i want Yii converts Y to Yes and N to No.

Whats the best way to do it?

Thank You!
0

#2 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 752
  • Joined: 02-February 09

Posted 19 February 2012 - 04:51 AM

'value'=>$model->fieldname=='Y' ? 'Yes':'No',
... or something like that should work :)
0

#3 User is offline   bulldoze 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 31-December 11

Posted 19 February 2012 - 04:49 PM

Thank You!

bettor logic works. just in case to another beginners, heres full code how it should look like:

'active' => array('label' => 'Active', 'value'=> ($model->active=='Y' ? 'Yes':'No') ),


if you add value in array then you should add label also. otherwise label field is empty.
0

#4 User is offline   sanat 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 26-September 12
  • Location:Caracas, Venezuela

Posted 16 February 2013 - 03:51 PM

View Postbulldoze, on 19 February 2012 - 04:49 PM, said:

Thank You!

bettor logic works. just in case to another beginners, heres full code how it should look like:

'active' => array('label' => 'Active', 'value'=> ($model->active=='Y' ? 'Yes':'No') ),


if you add value in array then you should add label also. otherwise label field is empty.


Very nice Bulldoze,

but let me ask, if you have to calculate the value, for example, suppose there is several values, not just two: yes and no, let me explain better, the value can be five letters. Another example, suppose you have to calculte the cost, which is an ecuation cost = price * quantity, and price and quantity are model's attributes. Can you built a function, like cGridView ?

Thanks
0

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