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

SortableDataObject not working


Reply


6 Posts   1063 Views

Avatar
Samba Sam

Community Member, 85 Posts

25 March 2010 at 7:54am

Edited: 25/03/2010 7:55am

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

Avatar
UncleCheese

Forum Moderator, 4093 Posts

25 March 2010 at 9:13am

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.

Avatar
Samba Sam

Community Member, 85 Posts

25 March 2010 at 1:02pm

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

Avatar
UncleCheese

Forum Moderator, 4093 Posts

25 March 2010 at 1:36pm

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

Avatar
Chris Hope

Community Member, 18 Posts

25 March 2010 at 4:33pm

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!

Avatar
Chris Hope

Community Member, 18 Posts

25 March 2010 at 4:37pm

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