Jump to:

7938 Posts in 1541 Topics by 945 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » many Attachments on FileDataObjectManager

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3
Go to End
Author Topic: 3790 Views
  • jmax
    Avatar
    Community Member
    17 Posts

    Re: many Attachments on FileDataObjectManager Link to this post

    Hi UncleCheese,

    it works. thx

    But the is no way use tha files lke variables.

    So my first question was is it possible have many files for each row?

    Example

    Name --- Surname --- Description --- Attachment1 --- Attachment2

    John Smith developer file1.zip file2.zip

    I saw in all example this schema works only with a single file.

    If i output with <% control Attchments %> i can't say that file2.zip is attachment2 and put it in a table td like a variable $Attachment

    Thank you for your support.
    Hi Max

  • UncleCheese
    Avatar
    4085 Posts

    Re: many Attachments on FileDataObjectManager Link to this post

    Right.. well, tables are for flat data models. You're trying to flatten a model that is no longer flat. If your model had only one file attachment, you could use a table column for that field, but since you're now saying you have any number of file attachments, you can't have a uniform table anymore. The column count would be different on each row!

  • jmax
    Avatar
    Community Member
    17 Posts

    Re: many Attachments on FileDataObjectManager Link to this post

    Thanks for your answer UncleCheese.
    Do you know if there is something to manage flat data models so i need?
    For each document of a section i need to manage many data with 3 attachment for each row..
    I don't know how i can do it..
    Bye

  • UncleCheese
    Avatar
    4085 Posts

    Re: many Attachments on FileDataObjectManager Link to this post

    What you're describing doesn't make any sense. You're asking that each row of the table have a different number of columns.

    Unless I'm misunderstanding you?

  • jmax
    Avatar
    Community Member
    17 Posts

    Re: many Attachments on FileDataObjectManager Link to this post

    Mhhh...

    perhaps I have not explained well my issue.

    I have a reserved area'ìè

    1- Reserved area have childrens that are pages of members.
    2 - Each page need to have dataobject to manage data of each members

    well, dataoject need to have 5 columns:

    Product Name, Description, Attachment1, Attachment2, Attachemnt3

    Attachment1, Attachment2 and Attachment3 are files.

    If i use only an Attachment all works ok. But if i need more than one file i don't know how do that.

    I hope have explain good this time ;-)

    sorry for my english..

  • UncleCheese
    Avatar
    4085 Posts

    Re: many Attachments on FileDataObjectManager Link to this post

    So you only have 3 attachments per object? Never more than that?

  • jmax
    Avatar
    Community Member
    17 Posts

    Re: many Attachments on FileDataObjectManager Link to this post

    Yes, but i need to manage the 3 attachments like variables.

    For example my output must be:

    <td>Name</td><td>Desc</td><td>File1</td><td>File2</td><td>File3</td>

    In the past post you tell me to use <% control Attachments %> but in this way i can't control them one by one

    I need to have an order to output files

    <td>Name</td><td>Desc</td><td>$File1</td><td>$File3</td><td>$File3</td>

    every in the same position

  • UncleCheese
    Avatar
    4085 Posts

    Re: many Attachments on FileDataObjectManager Link to this post

    So just do this:

    <?php
    class Resource extends DataObject
    {
    static $db = array (
    'Name' => 'Text',
    'Description' => 'Text',
    'Category' => "Enum('Industry, Finance, Education')",
    );

    static $has_one = array (
    'File1' => 'File',
    'File2' => 'File',
    'File3' => 'File',
    'ResourcePage' => 'ResourcePage'
    );

    public function getCMSFields_forPopup()
    {
    return new FieldSet(
    new TextField('Name'),
    new TextareaField('Description'),
    new DropdownField('Category','Category', singleton('Resource')->dbObject('Category')->enumValues()),
    new FileUploadField('File1'),
    new FileUploadField('File2'),
    new FileUploadField('File3')

    );
    }
    }
    ?>

    ==================================

    and this is the ResourcePage.php

    <?php
    class ResourcePage extends Page
    {
    static $has_many = array (
    'Resources' => 'Resource'
    );

    public function getCMSFields()
    {
    $f = parent::getCMSFields();
    $manager = new DataObjectManager(
    $this, // Controller
    'Resources', // Source name
    'Resource', // Source class
    array(
    'Name' => 'Name',
    'Description' => 'Description',
    'Category' => 'Category',
    'File1.Name' => 'File1',
    'File2.Name' => 'File2',
    'File3.Name' => 'File3',
    ), // Headings
    'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
    );

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

    return $f;
    }

    }

    class ResourcePage_Controller extends Page_Controller
    {
    }

    3790 Views
Page: 1 2 3
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.