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

SS3 confused with getManyManyComponents()


Go to End


3 Posts   1969 Views

Avatar
Stephan

Community Member, 55 Posts

28 January 2014 at 1:22am

Hi experts,
I can't get getManyManyComponents() working :(
I have extend a page of type product with

public static $many_many = array(
	'Images' => 'Image'	
);

So now I have a table called Product_Images with the comlumns ProductID and ImageID in my database.
Within the CMS I can attach images to my ProductPage and everything is working fine.

Now I want to access all images of a Product from a Shortcode.
(it has to come from a shortcode and not within the template itself)
I can get the current ProductID with Director::...... or from an argument of the shortcode.
And now I want to retrieve my images related to this ProductID.
But

$ProductImages = new Product_Images;
$images = $ProductImages->getManyManyComponents('Images', array('Product_Images.ProductID' => $intPageID));

doesn't work.

What am I doing wrong?

TIA Stephan

Avatar
swaiba

Forum Moderator, 1899 Posts

28 January 2014 at 2:44am

Hi Stephan,

try...

$product = //get product some how
$images = $product->Images();
foreach($images as $image) Debug::show($image);

Avatar
Stephan

Community Member, 55 Posts

28 January 2014 at 7:10am

Ok, that worked.
Many thanks :-)