Jump to:

7938 Posts in 1540 Topics by 945 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » FileDataObjectManager::__construct():Could not determine file relationship

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: 1280 Views
  • sajok
    Avatar
    Community Member
    82 Posts

    FileDataObjectManager::__construct():Could not determine file relationship Link to this post

    hello,

    I want to create a page for publications, so I created a PubHolder, PubPage and Publication classes as the following:

    PubHolder.php

    <?php

    class PubHolder extends Page {
    static $db = array(
    );
    static $has_one = array(
    );
    static $has_many = array(
    );
    static $icon = "ea/images/treeicons/books";
    static $allowed_children = array('PubPage');
    }

    class PubHolder_Controller extends Page_Controller {
    }

    PubPage.php :

    <?php
    class PubPage extends Page
    {
       static $has_many = array (
          'Publications' => 'Publication'
       );
    static $icon = "ea/images/treeicons/book-type";

       public function getCMSFields()
       {
          $f = parent::getCMSFields();
          $manager = new ImageDataObjectManager(
             $this, // Controller
             'Publications', // Source name
             'Publication', // Source class
             'photo', // File name on DataObject
             array(
                'Titre' => 'Titre',
                'Auteur' => 'Auteur',
                'Editeur' => 'Editeur'
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
             // Filter clause
             // Sort clause
             // Join clause
          );

          // If undefined, all types are allowed. Pass with or without a leading "."
          $manager->setAllowedFileTypes(array('jpg','gif','png'));

          // Label for the upload button in the popup
          $manager->setBrowseButtonText( _t('PubPage.UPLOADONLY', 'Photo (jpg, gif ou png)'));

          // In grid view, what field will appear underneath the icon. If left out, it defaults to the file title.
          $manager->setGridLabelField('Titre');

          // Plural form of the objects being managed. Used on the "Add" button.
          // If left out, this defaults to [MyObjectName]s
          $manager->setPluralTitle(_t('PubPage.UPLOADBUTTON', 'Publications'));

          $f->addFieldToTab("Root.Content.Publications", $manager);

          return $f;
       }
    }
    class PubPage_Controller extends Page_Controller
    {
    }

    Publication.php :

    <?php
    class Publication extends DataObject
    {
       static $db = array (
          'Titre' => 'Text',
    'Auteur' => 'Text',
    'Pages' => 'Text',
    'Version' => 'Text',
    'Editeur' => 'Text',
          'Description' => 'Text'
       );

       static $has_one = array (
          'Photo' => 'Image',
          'PubPage' => 'PubPage'
       );

       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Titre'),
    new TextField('Auteur'),
    new TextField('Pages'),
    new TextField('Version'),
    new TextField('Editeur'),
             new TextareaField('Description'),
             new FileIFrameField('Photo')
          );
       }
    }
    ?>

    I get this error in the admin cms whenever I create a PubPage!

    any help? thanks

  • UncleCheese
    Avatar
    4085 Posts

    Re: FileDataObjectManager::__construct():Could not determine file relationship Link to this post

    The file relationship is "Photo", not "photo".

    ---------------
    Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com

  • sajok
    Avatar
    Community Member
    82 Posts

    Re: FileDataObjectManager::__construct():Could not determine file relationship Link to this post

    this is really funny, I spent the whole day trying to detect where is the error and it turns out a letter case problem hhh..

    thank you AncleCheese

  • sajok
    Avatar
    Community Member
    82 Posts

    Re: FileDataObjectManager::__construct():Could not determine file relationship Link to this post

    one thing I didn't quite grasp: I tried has_one 'photo' => 'File' and it worked before, I'm using here has_one 'photo' => 'Image', is this the best option?

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