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

Display objects specific to just one page


Reply


4 Posts   492 Views

Avatar
ContentBloom

Community Member, 5 Posts

14 October 2011 at 12:02am

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?

Avatar
UncleCheese

Forum Moderator, 4096 Posts

14 October 2011 at 12:46am

Can we see your code for the page and dataobject classes?

---------------
Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com

Avatar
ContentBloom

Community Member, 5 Posts

14 October 2011 at 12:50am

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.Spotlights", $manager);

$fields->removeFieldFromTab("Root.Content.Main", 'Content');
      return $fields;
   }
}

class AwardsHolder_Controller extends Page_Controller {
   
   
}

Avatar
ContentBloom

Community Member, 5 Posts

14 October 2011 at 10:12pm

Does anyone have any ideas on this?