Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

FileDataObjectManager::__construct():Could not determine file relationship


Reply


4 Posts   1342 Views

Avatar
sajok

Community Member, 82 Posts

7 September 2010 at 10:28am

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

Avatar
UncleCheese

Forum Moderator, 4096 Posts

7 September 2010 at 11:49am

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

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

Avatar
sajok

Community Member, 82 Posts

7 September 2010 at 12:26pm

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

Avatar
sajok

Community Member, 82 Posts

7 September 2010 at 12:39pm

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?