21309 Posts in 5738 Topics by 2603 members
| Go to End | Next > | |
| Author | Topic: | 991 Views |
-
Problem adding mutiple images to page

23 July 2012 at 8:28am Last edited: 23 July 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
-
Re: Problem adding mutiple images to page

24 July 2012 at 9:46am
Has a better way, use Data Object Manager
http://www.silverstripe.org/dataobjectmanager-module/
http://doc.silverstripe.org/old/modules:dataobjectmanager -
Re: Problem adding mutiple images to page

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.
-
Re: Problem adding mutiple images to page

25 July 2012 at 1:01am Last edited: 25 July 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 %> -
Re: Problem adding mutiple images to page

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
-
Re: Problem adding mutiple images to page

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.
-
Re: Problem adding mutiple images to page

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.
-
Re: Problem adding mutiple images to page

8 February 2013 at 12:02am
can someone tell me how to add a variable to get the images instead of $SetWidth ?
| 991 Views | ||
| Go to Top | Next > |






