Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » best way

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: 332 Views
  • servalman
    Avatar
    Community Member
    211 Posts

    best way Link to this post

    Hello

    I have this project where I want to use dataobject and model admin :

    I need to create a structure like this :

    ITEM 1
    ressource 1
    ressource 2
    ressource 3

    ITEM 2
    ressource 1
    ressource 2
    ressource 3

    Every ressource level holds multiple files

    For now I have created my ressource level
    What I don't really get (I beggining with all this) is how I can go up one level and nest my ressources inside an ITEM

    Here is my code so far (I guess that Ressource page will be ItemPage at the end)

    code/ Resource.php:

    <?php
    class Resource extends DataObject
    {
       static $db = array (
          'Name' => 'Text',
          'Description' => 'Text',
       );
       
       static $has_one = array (
          'Attachment' => 'File',
          'ResourcePage' => 'ResourcePage'
       );
       
       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Name'),
             new TextareaField('Description'),
             new FileIFrameField('Attachment')
          );
       }
    }
    ?>

    also RessourceFile :

    <?php

    class ResourceFile extends File {

    static $has_one = array (
    'Resource' => 'Resource'
    );
    }

    and a RessourcePage.php

    <?php
    class ResourcePage extends Page
    {
       static $has_many = array (
          'Resources' => 'Resource'
       );
       
       public function getCMSFields()
       {
          $f = parent::getCMSFields();
          $manager = new FileDataObjectManager(
             $this, // Controller
             'Resources', // Source name
             'Resource', // Source class
             'Attachment', // File name on DataObject
             array(
                'Name' => 'Name',
                'Description' => 'Description'
             ),
          );
          
          
                
          $f->addFieldToTab("Root.Content.Resources", $manager);

          return $f;
       }

    }
    class ResourcePage_Controller extends Page_Controller {

    }

    }

    I f someone could guide me to a tutorial or docs explaining me this a bit it would be great

    Thanks

  • UncleCheese
    Avatar
    4085 Posts

    Re: best way Link to this post

    What is the purpose of ResourceFile?

  • servalman
    Avatar
    Community Member
    211 Posts

    Re: best way Link to this post

    Hello Uncle Cheese

    Ce fichier ne sert a rien (c'est l'une des nombreuse erreurs précédentes ;)

    Une fois que j'aurais pu résoudre mon problème sur les autres fichier je vais essayer d'adpater l'exemple http://doc.silverstripe.org/sapphire/en/reference/modeladmin a mon cas.

    Penses tu que cela soit une bonne solution ?

    Merci

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