Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » DataObject with link to 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: 837 Views
  • k0m0r
    Avatar
    Community Member
    39 Posts

    DataObject with link to page Link to this post

    Hi.
    I'm stuck at the following:

    class MyLink extends DataObject {

    public static $db = array(
    "Title" => "Varchar(255)",
    );

    public static $has_one = array(
    "ParentPage" => "SiteTree",
    "PagePointer" => "SiteTree",
    );

    function getCMSFields_forPopup() {
    $fields = new FieldSet();
    $fields->push(new TextField('Title','Link title'));
    $fields->push(new SimpleTreeDropdownField('PagePointerID','Select page'));      
    return $fields;
    }   
    }

    and on MyErrorPage :

    class MyErrorPage extends ErrorPage {

    public static $has_many = array(
    "LinkList" => "MyLink",
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();
          
    $manager = new DataObjectManager(
    $this,
    'LinkList',
    'MyLink',
    array(
    "Title" => "Title",
    ),
    'getCMSFields_forPopup'
    );

    $fields->addFieldToTab('Root.Content.LinkList',$manager);
    return $fields;
    }

    }

    When I comment out 'PagePointer' and SimpleTreeDropdownField from 'MyLink' class, everything works perfect. I can add MyLink items in DOM and then list them in a control (at MyErrorPage):

    <% control LinkList %>
    <li>$Title</li>
    <% end_control %>

    But after adding this:

    "PagePointer" => "SiteTree",

    and this:

    $fields->push(new SimpleTreeDropdownField('PagePointerID','Select page'));

    and rebuilding the database, LinkList control stops working. It doesn't matter if I set the value of PagePointerID or not, <% control LinkList %> is just empty, not a single item being shown.

    I triple checked everything, what am I missing here?

  • UncleCheese
    Avatar
    4085 Posts

    Re: DataObject with link to page Link to this post

    Your $has_many relationship is not reciprocated with a $has_one. Link needs to have a $has_one MyErrorPage (or wherever the DOM is). That's the data relationship that counts. $has_many just creates the template function.

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