Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Display objects specific to just one page

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 365 Views
  • ContentBloom
    Avatar
    Community Member
    5 Posts

    Display objects specific to just one page Link to this post

    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?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Display objects specific to just one page Link to this post

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

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

  • ContentBloom
    Avatar
    Community Member
    5 Posts

    Re: Display objects specific to just one page Link to this post

    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 {
       
       
    }

  • ContentBloom
    Avatar
    Community Member
    5 Posts

    Re: Display objects specific to just one page Link to this post

    Does anyone have any ideas on this?

    365 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.