Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Column Widths

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 2632 Views
  • UncleCheese
    Avatar
    4085 Posts

    Re: Column Widths Link to this post

    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
    ));

  • GustyPolo
    Avatar
    Community Member
    9 Posts

    Re: Column Widths Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Column Widths Link to this post

    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.

  • GustyPolo
    Avatar
    Community Member
    9 Posts

    Re: Column Widths Link to this post

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

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