Jump to:

3377 Posts in 1001 Topics by 714 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Escaping commas in Enum()

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

Page: 1
Go to End
Author Topic: 424 Views
  • mikhail
    Avatar
    Community Member
    4 Posts

    Escaping commas in Enum() Link to this post

    "Enum('Value1, Value2, Value3')"

    But what if I wanted:

    "Enum('Value 1, and some Value 2', 'Value 2, and a little bit of Value 7', 'Value3, cake and pie')"

    As far as I can tell there's no easy way to do this. I have tried escaping the commas in one string, tried passing it as multiple strings (which of course didn't work), even created this field with , ASCII commas in the hopes that it would write to DB in the raw format, but output in the proper encoding. This was probably the closest attempt at faking this, but the front-end fields are actually just outputting , as raw text.

    Feel free to ignore this, it's more of an aesthetics question, I have for now replaced the commas with + that should hopefully carry the same meaning.

  • kpolszewsk
    Avatar
    Community Member
    2 Posts

    Re: Escaping commas in Enum() Link to this post

    You could always create a custom field called e.g. "MySweetEnum", containing something like this:

    <?php
    class MySweetEnum extends Enum
    {

    public function __construct ( $name )
    {
    $enum = array (
    'Value 1, and some Value 2',
    'Value 2, and a little bit of Value 7',
    'Value3, cake and pie'
    );

    parent::__construct ( $name, $enum);
    }

    }

    and later use it like that:

    public static $db = array(
    'SomeEnumField' => 'MySweetEnum'
    );

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