Thanks... i have come up with this code...
Hotel.php
<?php
class Hotel extends DataObject
{
static $db = array (
'Name' => 'Text',
'LocationCity' => 'Text',
'Lat' => 'Text',
'Long' => 'Text'
);
static $has_many = array(
'HotelImages' => 'HotelImages'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Name' ) );
$fields->addFieldToTab( 'Root.Content.Main', new TextField( 'LocationCity' ) );
$fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Lat' ) );
$fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Long' ) );
return $fields;
}
}
class Hotel_Controller extends Page_Controller {}
HotelImages.php
<?php
class HotelImage extends DataObject {
static $db = array(
'Alt' => 'Text',
);
static $has_one = array (
'Attachment' => 'File',
'MyHotelImage' => 'Hotel'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Alt'),
new FileIFrameField('Attachment')
);
}
}
HotelPage.php
<?php
class HotelPage extends Page
{
static $has_many = array (
'Hotels' => 'Hotel'
);
public function getCMSFields()
{
$f = parent::getCMSFields();
$manager = new ImageDataObjectManager(
$this, // Controller
'Hotels', // Source name
'Hotel', // Source class
'Attachment', // File name on DataObject
array(
'Alt' => 'Alt'
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
// Filter clause
// Sort clause
// Join clause
);
$f->addFieldToTab("Root.Content.HotelImages",$manager);
return $f;
}
}
Which is a mash of code found on your mentioned tut, plus http://doc.silverstripe.org/old/modules:dataobjectmanager
All that happens when I try to add the page type is I get an error "There has been an error"
I am unsure where I went wrong.
In previous code I got a list of images added to the page fine, but I wanted to get the relationship right so I could extend with multiple tabs, i.e. one for images, then one for related other hotels.
Any help would be great!
thanks