Hello
I tried to modify Aram's great tutorial about dataobject as pages to be able to add many pictures, I kind of succeeded
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 (£)'
);
//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