Jump to:

7939 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » SortableDataObject not working

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: 1017 Views
  • Samba Sam
    Avatar
    Community Member
    85 Posts

    SortableDataObject not working Link to this post

    Hi,
    For some reason I am getting the following error when I try to rebuild the db with SortableDataObject::add_sortable_class('Link'); in my _config file: [Notice] Undefined variable: _SESSION

    These are my files:

    <?php
    class Link extends DataObject
    {
       static $db = array (
       'AltText' => 'Varchar(50)',
       'TitleText' => 'Varchar(50)',
       'Description' => 'HTMLText', // HTMLText does not convert html tags to plan text
       'LinkUrl' => 'Varchar(50)'
    );

       static $has_one = array (
       'LinksPage' => 'LinksPage',
       'LinkImage' => 'Image'
    );

    public function getDOMThumbnail()
       {return $this->LinkImage()->CroppedImage(50,50);}

    function getCMSFields()
    {
       return new FieldSet(
       new ImageField('LinkImage'),
       new TextField('AltText'),
       new TextField('TitleText'),
       new TextField('Description'),
       new TextField('LinkUrl'));
    }
    }
    ?>

    <?php
    class LinksPage extends Page
    {
    static $has_many = array (
    'Links' => 'Link'
    );

    public function getCMSFields()
       {
          $fields = parent::getCMSFields();
          $manager = new DataObjectManager(
    $this,
    'Links',
    'Link',
    array(
    'DOMThumbnail' => 'Thumbnail',
    'AltText' => 'AltText',
    'TitleText' => 'TitleText',
    'Description' => 'Link description',
    'LinkUrl' => 'Url of link'
    ),
    'getCMSFields_forPopup'
    );
          $fields->addFieldToTab("Root.Content.Links", $manager);
          return $fields;
       }

    } // END of LinksPage
    class LinksPage_Controller extends Page_Controller
    {
    } // END of LinksPage_Controller
    ?>

    Any ideas?
    Sam

  • UncleCheese
    Avatar
    4085 Posts

    Re: SortableDataObject not working Link to this post

    You've got whitespace somewhere. Check all your PHP files and make sure there isn't any content being sent to the browser. You're closing your PHP tags.. you should remove those to prevent errors like this.

  • Samba Sam
    Avatar
    Community Member
    85 Posts

    Re: SortableDataObject not working Link to this post

    Thanks Uncle Cheese!
    Yup, there was white space at the end of the Link.php file that was creating the error. Removed it, now the sortable object works.
    So, are you saying to use the opening php tag "<?php" but not the closing one "?>" as a general rule of thumb in my SS php files?

    Sam

  • UncleCheese
    Avatar
    4085 Posts

    Re: SortableDataObject not working Link to this post

    Yeah, in an MVC framework, you should never have to close a PHP tag.

  • Chris Hope
    Avatar
    Community Member
    18 Posts

    Re: SortableDataObject not working Link to this post

    I found this forum thread when looking for how to sort something in SS. I've now found the http://doc.silverstripe.org/doku.php?id=modules:sortabledataobject page but can't actually see where to download the module from. I've looked in the modules pages but can't see it there. Where do I get it from? Thanks!

  • Chris Hope
    Avatar
    Community Member
    18 Posts

    Re: SortableDataObject not working Link to this post

    Ah never mind, I found it's contained within this extremely useful module which the forum topic is all about

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