Jump to:

23455 Posts in 18904 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Can I access data from getCMSFields?

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: 208 Views
  • Raver0124
    Avatar
    Community Member
    8 Posts

    Can I access data from getCMSFields? Link to this post

    Hi guys,

    I'm new in SilverStripe and i'm not quite sure i can do this.
    Can i access the data from getCMSField?

    class ImageDemo extends Page
    {
    static $db = array(
    'Title' => 'Varchar'
    );

    static $has_one = array(
    'Graphic' => 'Image'
    );

    public function getCMSFields($params = null){
    $fields = parent::getCMSFields($params);

    if ($this->Graphic.exists()) { <--------------- I wanna check if the data exist in Graphic

    $fields->addFieldToTab("Root.Content.Main", new UploadField('Graphic', "A Feature Image"), "Content");

    }
    else
    {
    $fields->addFieldToTab("Root.Content.Main", new TextField('Graphic', "A Feature Image"), "Content");
    }
    return $fields;
    }
    }

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Can I access data from getCMSFields? Link to this post

    The answer is sometimes. You can for edit forms but on creation the form values will not be set. You could do something like if($this->Graphic() && $this->Graphic()->exists()) { // ...

  • Raver0124
    Avatar
    Community Member
    8 Posts

    Re: Can I access data from getCMSFields? Link to this post

    Thank you very much, that worked perfectly

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