Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Possibility to have hasmany relation to be different on every 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: 399 Views
  • quanto
    Avatar
    Community Member
    81 Posts

    Possibility to have hasmany relation to be different on every page? Link to this post

    i'm trying to get a Tab "Fotos" Wherein the enduser has the possibility to upload thumbnails and photo's. The upload module works, except every page shows the same pictures. I think it's in the fotos.php static has_one -> SiteTree, because of it stays 0 in the db after saving.

    I want to have every page different pictures (eg home: 1.jpg, 2.jpg; contact: 3.jpg, 4.jpg),

    Foto's.php:

    <?php
    /**
    * Defines the Fotos
    */
    class Fotos extends DataObject {
    static $db = array(
    'SmallCapt' => 'Text',
    'LargeCapt' => 'Text'
    );

    static $has_one = array(
    'SmallFoto' => 'Image',
    'LargeFoto' => 'Image',
    'MySiteTree' => 'SiteTree'
    );

    function getCMSFields_forPopup() {
    $fields = new FieldSet();

    $fields->push( new SimpleImageField( 'SmallFoto', 'Kleine foto') );
    $fields->push( new Textfield( 'SmallCapt', 'Beschr. kleine foto' ) );
    $fields->push( new SimpleImageField( 'LargeFoto', 'Grote foto' ) );
    $fields->push( new Textfield( 'LargeCapt', 'Beschtr. grote foto' ) );

    return $fields;
    }
    }
    ?>

    Page.php

    ...
    public static $has_many = array(
    'MyFotos' => 'Fotos'
       );

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $tablefield = new HasManyComplexTableField(
    $this,
    'MyFotos',
    'Fotos',
    array(
    'SmallFoto' => 'Kleine foto',
    'SmallCapt' => 'Beschrijving',
    'LargeFoto' => 'Grote foto',
    'LargeCapt' => 'Beschrijving'
    ),
    'getCMSFields_forPopup'
    );

    $fields->addFieldToTab('Root.Content.Fotos', $tablefield );
    return $fields;
    }
    ...

  • UncleCheese
    Avatar
    4085 Posts

    Re: Possibility to have hasmany relation to be different on every page? Link to this post

    Well you're in the DataObjectManager forum, so I can only troubleshoot HasManyDOM, not HasManyCTF.

    I would use a HasManyFileDOM and use setParentClass("SiteTree") in this case.

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

  • quanto
    Avatar
    Community Member
    81 Posts

    Re: Possibility to have hasmany relation to be different on every page? Link to this post

    Ok thanks, i will repost this in the regular forum.

    399 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.