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.

General Questions /

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

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

Problem adding mutiple images to page


Go to End
Reply


13 Posts   2534 Views

Avatar
Pix

Community Member, 153 Posts

23 July 2012 at 8:28am

Edited: 23/07/2012 8:30am

Hi All,

I have a custom page with multiple images, and everything is working fine. It's built like this right now:

static $has_one = array(
      'Photo' => 'Image',
       'PhotoTwo' => 'Image',
       'PhotoThree' => 'Image',
       'PhotoFour' => 'Image',
       'PhotoFive' => 'Image',
       'SmallBanner' => 'Image'
   );

The problem comes when I try to add just one more image, it blows up the site and I get "Sorry, there was a problem handling your request". I am using SS 2.4.5. Is there some sort of limit? Or a better way to do it? Or am I just missing something (besides brain cells)?

Thanks

Avatar
Hattori

Community Member, 20 Posts

24 July 2012 at 9:46am

Avatar
svandragt

Community Member, 44 Posts

25 July 2012 at 12:41am

Data Object Manager is not yet compatible with SilverStripe 3?

[User Deprecated] DataObjectDecorator->__construct is deprecated. Use DataExtension instead. Called from ReflectionClass->newInstance.

Avatar
svandragt

Community Member, 44 Posts

25 July 2012 at 1:01am

Edited: 25/07/2012 1:08am

I just got this working, you do not need to install any module anymore in SilverStripe 3.0:

Because the UploadField can now handle multiple files/images, we simply specify a has_many relationship and create a screenshot class that extends the Image DataObject. Remember to set a link back from the dataobject to the page type:

In
mysite/code/YourPage.php:

class YourPage extends Page {

	public static $has_many = array(
		'Screenshots' => 'Screenshot'
	);

	public function getCMSFields() {
		$fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.Main', new UploadField('Screenshots'), 'Content');
		return $fields;
	}
}

class Screenshot extends Image {
		public static $has_one = array(
			'YourPage' => 'YourPage'
	);	
}

Then, in your theme's
templates/Layout/YourPage.ss, we can just call the has_many relationship and use all the Image class's methods:

<div class="content-container typography">	
	<article>
		<h1>$Title</h1>
		<div class="content">
				<% loop Screenshots %>
					$SetWidth(320)
				<% end_loop %>
			$Content
		</div>
	</article>
		$Form
		$PageComments
</div>
<% include SideBar %>

Avatar
Pix

Community Member, 153 Posts

25 July 2012 at 5:47am

Hi,

Thanks for all the replies. That looks like a good solution. Haven't upgraded to 3.0 yet, I guess I better do that

For now I just can't see why the current code is bombing....is there a quick and easy fix?

Thanks

Avatar
MartinPhone

Community Member, 57 Posts

15 November 2012 at 1:47pm

Thanks for this. Still trying to get my head around what SS3 can and can't do and this example was just what I needed.

Avatar
congii

Community Member, 6 Posts

31 January 2013 at 5:37pm


Hi, this works on the CMS side, in the front-end form I can't seem to make this work using FileField.

Avatar
mimamo

Community Member, 22 Posts

8 February 2013 at 12:02am

can someone tell me how to add a variable to get the images instead of $SetWidth ?

Go to Top