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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

ListboxField for Many_Many - Roadmap help needed!


Go to End


3 Posts   1085 Views

Avatar
MartinPhone

Community Member, 57 Posts

7 May 2013 at 11:22am

Edited: 07/05/2013 11:28am

I've made a few sites with SS - I'm by no means an expert and I make sites just for friends and family, but I'm familiar with extending a site etc. I'm just needing a little help seeing the bigger picture. Just getting a bit confused at the moment.

The site in question, if you're interested is this - http://thelittleescape.com The site has been live for about a year and the way in which it has been used suggests a little restructuring.

It's a clinic where one Practitioner may offer various Treatments and each Treatment can be offered by more than one Practitioner.

I want to link to the many Treatments offered by each Practitioner on their pages, and the many Practitioners who offer each Treatment on those pages. (The aim is to remove the page listing the billions of Practitioners as it's a bit pointless and there's too much duplication of content).

Now this is where it gets fuzzy.

I'm not quite sure if I need distinct Treatment and Practitioner objects if I've already got TreatmentPage and PractitionerPage as I can surely put all the extra data/functions/whathaveyou in there? If I have separate objects - I'm looking and many_many and belongs_many_many - can pages be many_many? Does that even make sense? I guess each Treatment object will have a $has_one for the TreatmentPage... but that seems a bit pointless... as I said. Fuzzy.

It seems most sensible to have a ListboxField or checkboxsetField on the Practitioner CMS page populated by querying the DB for all the Treatments but (and this seems to be my stumbling block) I can't populate the ListboxField despite many attempts, following where other forum posts have gone before.

My aim - we set the Treatments offered within each Practitioner page in the CMS, and everything works both ways (see Treatments from Practitioners' pages and vice versa).

Ultimately, I'm just not sure I'm even going about this in the right way and any advice would be appreciated! Very sorry if any of this is too vague, or too specific.

Avatar
Bambii7

Community Member, 254 Posts

9 May 2013 at 4:14pm

Sounds right, Practitioner will have many_many Treatments & Teatments belong_many_many Parctitioner.
Pages can have a relationship with other pages this way, or with has_one or has_many

PractitionerPage extends Page {
$many_many = array('teatments' = > 'TreatmentPage');
}

TreatmentPage extends Page {
$belongs_many_many = array('practitioners' = > 'PractitionerPage');
}

So on the treatment page you can use
<% control practitioners %>

And on the practitioners page
<% control teatments %>

Have a go, if you get stuck, come back and post code examples :p thats what I do.

Avatar
MartinPhone

Community Member, 57 Posts

12 May 2013 at 3:07pm

Thanks a lot for this. much much appreciated. I will give it a shot.