I'm fairly new to SilverStripe so please forgive me if this seems simple. I've had a search of the forum and read the documentation but couldn't see what I'm after.
I'm using the dataobjectmanager to add slideshow images to a page. If I create one page with slideshow images and then create a new page from the same page type, the slideshow images are already populated with the ones from the first page. I guess they're added as global assets?
Is there a way to add objects to just one page with the dataobjectmanager?
This is my slide/dataobject code...
<?php
class Slide extends DataObject {
/**
*
* DB fields
* @var unknown_type
*/
static $db = array (
'Title' => 'Varchar(255)',
'Text' => 'Text',
'Link' => 'Text'
);
/**
*
* Relations
* @var array
*/
static $has_one = array (
'HomePage' => 'HomePage',
'Image' => 'Image'
);
/**
*
* /Fields to show in the DOM table
* @var array
*/
static $summary_fields = array(
'Thumb' => 'Image',
'Title' => 'Title',
'Text' => 'Text',
'Page link' => 'Link'
);
/**
* (non-PHPdoc)
* @see httpdocs/sapphire/core/model/DataObject::getCMSFields()
*/
public function getCMSFields()
{
return new FieldSet(
new TextField('Title'),
new TextField('Text'),
new TextField('Link'),
new ImageField('Image', 'Image', null, null, null, 'slides')
);
}
/**
*
* Generate our thumbnail for the DOM
*/
public function getThumb()
{
if($this->ImageID)
return $this->Image()->CMSThumbnail();
else
return '(No Image)';
}
}
This is my page code
<?php
class AwardsHolder extends Page {
static $db = array(
);
static $has_many = array(
'Slides' => 'Slide',
'Spotlights' => 'Spotlight'
);
static $allowed_children = array('ArticlePage');
public function getCMSFields() {
$fields = parent::getCMSFields();
$manager = new DataObjectManager(
$this,
'Slides',
'Slide'
);
$fields->addFieldToTab("Root.Content.Slideshow", $manager);
$manager = new DataObjectManager(
$this,
'Spotlights',
'Spotlight'
);
$fields->addFieldToTab("Root.Content.Spotligh开发者_JAVA百科ts", $manager);
$fields->removeFieldFromTab("Root.Content.Main", 'Content');
return $fields;
}
}
class AwardsHolder_Controller extends Page_Controller {
}
In your relationships you have specified that a Slide
has_one HomePage
, but it should be AwardsHolder
. I'd start by looking at that first.
精彩评论