Jump to:

23375 Posts in 18175 Topics by 2866 members

General Questions

SilverStripe Forums » General Questions » FileIFrameField not working in getCMSFields_forPopup

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: 1944 Views
  • andy_steel
    Avatar
    Community Member
    31 Posts

    FileIFrameField not working in getCMSFields_forPopup Link to this post

    Hi,

    I'm trying to attach multiple files to a page. I'm using HasManyComplexTableField and FileIFrameField.
    I get the following error on the pop-up window:

    Notice: Trying to get property of non-object in C:\Projects\myproject\src\sapphire\forms\FileIFrameField.php on line 18

    What am I doing wrong?

    Here is my code:

    <?php

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

       static $has_one = array(
       );
       static $has_many = array(
          'ProjectAssets' => 'ProjectAsset',
       );

       function getCMSFields()
       {
          $fields = parent::getCMSFields();

          $tablefield = new HasManyComplexTableField(
                $this,
                'ProjectAssets',
              'ProjectAsset',
              array(
                 'FileTitle' => 'Title'
              ),
              'getCMSFields_forPopup'
          );
          $tablefield->setAddTitle('file');
          $fields->addFieldToTab( 'Root.Content.Files', $tablefield );

          return $fields;
       }
    }

    class Project_Controller extends Page_Controller
    {
    }

    ?>
    <?php

    class ProjectAsset extends DataObject {
       static $db = array(
          'FileTitle' => 'Varchar(200)'
       );
    static $has_one = array(
          'Project' => 'Project',
          'File' => 'File'      
       );
       function getCMSFields_forPopup() {
          return new FieldSet(
             new TextField('FileTitle', 'Title'),
             new FileIFrameField('File')
          );
       }
    }

    ?>

  • UncleCheese
    Avatar
    4085 Posts

    Re: FileIFrameField not working in getCMSFields_forPopup Link to this post

    This is a known bug. Look at line 18 of FileIFrameField in /sapphire/forms. You'll see it's trying to access a variable that may not necessarily be defined (I believe it's called $data). Use the isset() function to determine if the variable is set before going any further.

  • andy_steel
    Avatar
    Community Member
    31 Posts

    Re: FileIFrameField not working in getCMSFields_forPopup Link to this post

    That fixed it. Thanks Uncle cheese!

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