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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

SortableDataObject problem [SOLVED]


Reply


3 Posts   773 Views

Avatar
Possibles

Community Member, 16 Posts

23 November 2011 at 6:36am

Hello

I tried to modify Aram's great tutorial about dataobject as pages to be able to add many pictures, I kind of succeeded

[url]http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-2-using-model-admin-and-url-segments-to-create-a-product-catalogue/[/url]

I have now another problem I wanted to be able to sort (via drag and drop) the photos. I tried :

SortableDataObject::add_sortable_classes((Photo')); in _config.php

but I get error :
Error: "Couldn't run query: SELECT "Photo"."ClassName", "Photo"."Created", "Photo"."LastEdited", "Photo"."Name", "Photo"."Description", "Photo"."SortOrder", "Photo"."AttachmentID", "Photo"."ProductID", "Photo"."ID", CASE WHEN "Photo"."ClassName" IS NOT NULL THEN "Photo"."ClassName" ELSE 'Photo' END AS "RecordClassName" FROM "Photo" ORDER BY "SortOrder" ASC LIMIT 10 OFFSET 0 Unknown column 'Photo.SortOrder' in 'field list'" at line 525 of /var/www/vhosts/possibles.net/httpdocs/silvertest/sapphire/core/model/MySQLDatabase.php

Here are the codes :
Photo.php

<?php

class Photo extends DataObject {

static $db = array(
    'Name' => 'Text',
      'Description' => 'Text',
);

static $has_one = array(
'Attachment' => 'Image',
'Product' => 'Product'
);
public function getCMSFields_forPopup()
   {
      return new FieldSet(
         new TextField('Name'),
         new TextareaField('Description'),
         new FileIFrameField('Attachment')
      );
   }
}

?>

Product.php

class Product extends DataObject
{
   static $db = array(
      'Title' => 'Varchar(255)',
      'Description' => 'HTMLText',
      'Price' => 'Decimal(6,2)',
      'URLSegment' => 'Varchar(255)',
      'MetaTitle' => 'Varchar(255)'
   );

   //Set our defaults
   static $defaults = array(   
      'Title' => 'New Product',
      'URLSegment' => 'new-product'
   );
   
   static $has_many = array(
      'Photos' => 'Photo'
   );
   
   //Relate to the category pages
   static $belongs_many_many = array(
      'Categories' => 'CategoryPage'
   );
   
   //Fields to show in ModelAdmin table
   static $summary_fields = array(
      'Title' => 'Title',
      'URLSegment' => 'URLSegment',
      'Price' => 'Price (&pound;)'
   );   

   //Add an SQL index for the URLSegment
   static $indexes = array(
      "URLSegment" => true
   );   

   //Fields to search in ModelAdmin
   static $searchable_fields = array (
      'Title',
      'URLSegment',
      'Description',
      'Categories.ID' => array(
         'title' => 'Category'
      )
   );

   public function getCMSFields()
   {
      $f = parent::getCMSFields();
      $manager = new FileDataObjectManager(
         $this, // Controller
         'Photos', // Source name
         'Photo', // Source class
         'Attachment', // File name on DataObject
         array(
            'Title' => 'Title',
            'Producers' => 'Producers',
            'URLSegment' => 'URL Segment',
            'MetaTitle' => 'Meta Title',
            'YearOfFabrication' => 'YearOfFabrication',
            'Price' => 'Price',
            'Description' => 'Description'
         ), // Headings
         'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
         // Filter clause
         // Sort clause
         // Join clause
      );
      $f->addFieldToTab("Root.Photos", $manager);
      //Categories
      $Categories = DataObject::get('CategoryPage');
      $f->addFieldToTab("Root.Categories", new CheckboxsetField('Categories', 'Categories', $Categories));
return $f;

      
   }
......

ProductAdmin

<?php

class ProductAdmin extends ModelAdmin {

   public static $managed_models = array(
      'Product'
   );
   
   static $url_segment = 'products';
   static $menu_title = 'Products';
   
}

Thanks

Avatar
martimiz

Forum Moderator, 1132 Posts

23 November 2011 at 7:34am

Did you do a /dev/build/?flush=1 to update the database?

Avatar
Possibles

Community Member, 16 Posts

23 November 2011 at 11:52pm

That was it !

I have got to change my brain

Thanks