Jump to:

7938 Posts in 1541 Topics by 945 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Date field wont save!

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 966 Views
  • vegetav
    Avatar
    Community Member
    23 Posts

    Date field wont save! Link to this post

    I'm trying to make simple use of the DataObjectManager, I need Date, Title, and a PDF file upload. I've got it working apart from everytime I save, it doesn't save the date, only the title. This is my code...

    PdfFile.php:

    <?php

    class PdfFile extends DataObject
    {
       static $db = array (
          'Date' => 'Date',
          'Title' => 'Text'
       );

       static $has_one = array (
          'PDF' => 'File',
          'FilePage' => 'FilePage'
       );

       public function getCMSFields_forPopup()
       {
    $dateField = new DateField('Date');
    $dateField->setConfig('showcalendar', true);
          return new FieldSet(
             $dateField,
             new TextField('Title'),
             new FileField('PDF')
          );
       }
    }

    ?>

    FilePage.php:

    <?php

    class FilePage extends Page
    {
    static $db = array (
    );

    static $has_one = array (
    );

    static $has_many = array (
    'PdfFiles' => 'PdfFile'
    );

    public function getCMSFields()
    {
    $f = parent::getCMSFields();
    $f->addFieldToTab("Root.Content.PDF", new DataObjectManager(
    $this,
    'PdfFiles',
    'PdfFile',
    array('Date'=>'Date', 'Title'=>'Title'),
    'getCMSFields_forPopup'
    ));

    return $f;
    }
    }

    class FilePage_Controller extends Page_Controller {
    }

    ?>

    Any advice would be much appreciated!

    Many thanks,
    Vic

  • UncleCheese
    Avatar
    4085 Posts

    Re: Date field wont save! Link to this post

    Just use a DatePickerField.

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