Hi all,
Firstly, I'd like to say how exciting SilverStripe is in its possibilities and can't wait to become a fully fledged developer & contributor to the community.
My understanding of PHP is limited, and maybe that is why I'm finding it hard to make the penny drop with SilverStripe, but I'm an advanced AS3 developer, so I know when it all falls into place in my head I can build some momentum (and websites). I'm just going round in silly logical circles at the mo.
I'm a little stuck with a very simple task. Just wanted to know the best way to do it.
It's for my portfolio website. I've got Page subclasses PortfolioList & PortfolioItem and a DataObject subclass PortfolioImage. PorfolioItem is a child of PortfolioList and PortfolioItem 'has many' PortfolioImages, which I'm successfully managing in the CMS using ImageDataObjectManager, which I admit is the only reason I'm posting in this particular forum.
What I would like to do in the PortfolioList template is output each PortfolioItem in a box with its first PortfolioImage as a thumbnail of a certain width.
Here're my PortfolioItem & PortfolioioImage classes:
class PortfolioItem extends Page
{
static $db = array(
'categoryWeb' => 'Boolean',
'categoryFlash' => 'Boolean'
);
static $has_one = array(
);
static $has_many = array(
'Images' => 'PortfolioImage'
);
function getCMSFields()
{
$fields = parent::getCMSFields();
$manager = new ImageDataObjectManager(
$this, // Controller
'Images', // Source name
'PortfolioImage', // Source class
'Image', // File name on DataObject
array('ImageTitle' => 'ImageTitle'), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
// Filter clause
// Sort clause
// Join clause
);
$fields->addFieldToTab('Root.Content.Main', new CheckboxField($name = 'category_web', $title = 'Web'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new CheckboxField($name = 'category_flash', $title = 'Flash'), 'Content');
$fields->addFieldToTab('Root.Content.Images', $manager);
return $fields;
}
}
class PortfolioImage extends Image
{
static $db = array(
'ImageTitle' => 'Text'
);
static $has_one = array(
'Image' => 'Image',
'PortfolioItem' => 'PortfolioItem'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('ImageTitle', 'Image Title')
);
}
}
This is what I've got so far in the PortfolioList template. For now I'm just outputting the PortfolioImage URLs to see that it's working, and it is:
<% control Children %>
<div class="box box-portfolio">
<div class="box-element box-tl"></div><div class="box-element box-tc"></div><div class="box-element box-tr"></div>
<div class="box-element box-middle">
<% control Images %><p>$Link</p><% end_control %>
<!--<a href="$Link"><img src="" alt="Screenshot" /></a>-->
<h2><a href="$Link">$Title</a></h2>
</div>
<div class="box-element box-bl"></div><div class="box-element box-bc"></div><div class="box-element box-br"></div>
</div><!--/box-portfolio-->
<% end_control %>
So, would I create a function in PortfolioItem to get the first image? Also would I create a function in PortfolioImage generate a set thumbnail size? Or is there a better way?
Would sopmeone be able to provide some real code examples of how I could achieve this, with some basic explanation? Maybe this will help me understand the structure of SilverStripe just that bit more and I can move on to the next notch.
My sincere thanks and apologies!
Tim