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

many Attachments on FileDataObjectManager


Reply


24 Posts   4050 Views

Avatar
jmax

Community Member, 17 Posts

2 February 2011 at 9:46pm

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

Avatar
UncleCheese

Forum Moderator, 4096 Posts

4 February 2011 at 4:48am

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!

Avatar
jmax

Community Member, 17 Posts

4 February 2011 at 4:56am

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

Avatar
UncleCheese

Forum Moderator, 4096 Posts

4 February 2011 at 5:45am

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?

Avatar
jmax

Community Member, 17 Posts

4 February 2011 at 6:02am

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

Avatar
UncleCheese

Forum Moderator, 4096 Posts

4 February 2011 at 6:47am

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

Avatar
jmax

Community Member, 17 Posts

4 February 2011 at 7:10am

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

Avatar
UncleCheese

Forum Moderator, 4096 Posts

4 February 2011 at 7:31am

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
{
}