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

Column Widths


Go to End
Reply


12 Posts   2913 Views

Avatar
UncleCheese

Forum Moderator, 4094 Posts

9 October 2009 at 6:31am

You can just do it in your getCMSFields() function.

$fields->addFieldToTab("Root.Content.Audio Files", $dom = new FileDataObjectManager($this));
$dom->setColumnWidths(array(
'Date' => 20,
'Description' => 80
));

Avatar
GustyPolo

Community Member, 9 Posts

9 October 2009 at 6:40am

Thanks for the quick response :) I'm a little more lost. What I'm doing to get the mp3 upload is modifying the ResourcePage Tutorial to make it work for mp3. It might be the wrong way of doing it but so far it's working. So this is what i have:

Resource.php:

class Resource extends DataObject
{
static $db = array (
'Name' => 'Text',
'Date' => 'Date',
'Description' => 'Text',

);

static $has_one = array (
'Attachment' => 'File',
'ResourcePage' => 'ResourcePage'

);

public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Name'),
new CalendarDateField('Date'),
new TextareaField('Description'),
new FileIFrameField('Attachment')
);
}

}

ResourcePage.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',
'Date' => 'Date',
'Description' => 'Description',
), // 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('mp3'));

// Label for the upload button in the popup
$manager->setBrowseButtonText("Upload mp3");

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

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

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

return $f;
}

function MyFileObjects()
{
$filter = Director::urlParam('Action');
return $filter ? $this->Resources("Category = '$filter'") : $this->Resources();
}

}
class ResourcePage_Controller extends Page_Controller

{
function category()
{
$resources = DataObject::get("Resource","Category='".$this->urlParams['ID']."'");
if($resources) {
return $this->customise(array(
'Resources' => $resources,
'CategoryTitle' => $this->urlParams['ID']
));
}
return false;
}
}

?>

ResourcePage.ss

<% if Resources %>
<% control Resources %>
<hr>

<h1>$Name</h2>
<p>$Description</p>
<a href="$Attachment.URL">Download</a>

<% end_control %>
<% end_if %>

---------

I'm sure there are pieces of code that are redundant and dont need to be there, but taking certain things off doesn't go well when I run a dev/build.

this is pretty much my first attempt at creating a site using cms so any help you can give me helps. I have other quesitons too, but I'll look around in the forum to see if it's been asked.

Thanks.

Avatar
UncleCheese

Forum Moderator, 4094 Posts

9 October 2009 at 7:18am

Edited: 09/10/2009 7:18am

So right before this:

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

add:

$manager->setColumnWidths(array(
'Name' => 40,
'Date' => 20,
'Description' => 40
));

Just has to add up to 100.

Avatar
GustyPolo

Community Member, 9 Posts

9 October 2009 at 10:30am

Thank you very much for this. Slowly im starting to grasp how Silverstripe works in the back end.

Go to Top