Hi there,
I am trying to get first image from image gallery with croppedResize. I can only retrieve the first image but the croppedResize doesn't work.
ProductPage.php
<?php
/**
* Defines the ProductPage page type
*/
class MyImage extends Image {
function generateSmallimage($gd) {
return $gd->croppedResize(65,65);
}
}
class ProductPage extends Page {
static $defaults = array(
'ProvideComments' => true
);
static $db = array(
'Price' => 'Text',
'Brief' =>'Text',
'Date' => 'Date'
);
static $has_many = array ('GalleryImages' => 'GalleryImage');
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TextField('Price', 'Product Price'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('ProductIntro','Introduction'), 'Content');
$fields->addFieldToTab('Root.Content.Main', $dateField = new DateField('Date','Date (for example: 20/02/2011)'), 'Content');
$dateField->setConfig('showcalendar', true);
$dateField->setConfig('dateformat', 'dd/MM/YYYY');
$manager = new ImageDataObjectManager(
$this, // Controller
'GalleryImages', // Source name
'GalleryImage', // Source class
'MyGalleryImage', // File name on DataObject
array(
'GalleryImageTitle' => 'GalleryImageTitle'
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
// Filter clause
// Sort clause
// Join clause
);
$fields->addFieldToTab('Root.Content.GalleryImage',$manager);
return $fields;
}
}
class GalleryImage extends DataObject
{
static $db = array (
'GalleryImageTitle' => 'Text'
);
static $has_one = array (
'MyGalleryImage' => 'Image',
'BelongToProductPage' => 'ProductPage'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('GalleryImageTitle'),
new FileIFrameField('MyGalleryImage')
);
}
}
class ProductPage_Controller extends Page_Controller {
}
?>
ProductHolder.ss
<div id="content" class="typography">
<h1>$Title</h1>
$Content
<div id="itemlist">
<ul>
<% control Children %>
<li>
<a href="$Link" title="Read more on "{$Title}"">
<% if GalleryImages %>
<% control GalleryImages.First.Smallimage %>
<img src="$MyGalleryImage.URL"/>
<% end_control %>
<% end_if %>
<h3>$Title</h3>
</a>
<p>$Content.FirstParagraph <a href="$Link" title="Read more on "{$Title}"">Read more >></a></p>
</li>
<% end_control %>
</ul>
</div>
</div>
I really need help otherwise can't go to bed :(
Bunheng