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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Listing dataobjects with ListboxField


Go to End


1102 Views

Avatar
sweetroll

Community Member, 1 Post

4 September 2012 at 7:28pm

Hey,

I have a many to many relationship between a DataObject (Tag) and a Page and am wanting to manage the relationship through a multiple select.

At the moment I am stuck with the following code

 $tagsField = new ListboxField(
      'Tags',
      'Tags',
      Tag::get()->toArray("ID", "Name"),
      $this->Tags()->toArray("ID", "Name"),
      null,
      true
    );  

Error: Object->__call(): the method 'fortemplate' does not exist on 'Tag'

I know this code won't currently allow me to add new tags but I would like to get my head around how to link existing tags with a page.

Hopefully I am not too far off.

Cheers.