Jump to:

23550 Posts in 19336 Topics by 2890 members

General Questions

SilverStripe Forums » General Questions » Boolean->Nice in ModelAdmin

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1152 Views
  • swaiba
    Avatar
    Forum Moderator
    1796 Posts

    Boolean->Nice in ModelAdmin Link to this post

    Hi,

    In the ss book (when created a TableListField for displaying data) there is a line to cast Boolean data into 'Boolean->Nice' so that instead of Value (field name) and 0 or 1 (data) instead appears Value? and Yes or No.

    Is there away to apply this to ModelAdmin please?

    Barry

  • swaiba
    Avatar
    Forum Moderator
    1796 Posts

    Re: Boolean->Nice in ModelAdmin Link to this post

    found the answer...

    static $casting = array(
    "MyTextBoolean" => "Text"
    );

    public static $summary_fields = array (
       ...
       'MyTextBoolean'=>'IsTrue?',
    );

    public function MyTextBoolean()
    {
       $str = 'No';
       if ($this->BooleanField== true)
          $str = 'Yes';

       return $str;
    }

    1152 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.