7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » has-many images using imagedataobjectmanager
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1428 Views |
-
has-many images using imagedataobjectmanager

16 September 2010 at 11:43pm
Hi, I trying to create a portfolio of website. Each website with an unlimited amount of images. I have got it working with the new ImageField but this imits the amount of images I can upload.
At the moment I have it working to display all the images but there is no relation to the website just all the images I have uploaded.
Website.php
<?php
class Website extends Page {
static $db = array (
'Featured' => 'Boolean',
'Completion' => 'Date'
);
static $has_one = array(
'Website_Browse' => 'Website_Browse'
);
static $has_many = array(
'Images' => 'Image'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->renameField('Title', 'Website Title');
$fields->addFieldToTab('Root.Content.Main', new CheckboxField(
$name = "Featured",
$title = "<strong>Featured Website</strong> - Check to display on the homepage"),
'Content');
$fields->addFieldToTab("Root.Content.Main", new DateField('Completion'));$images = new ImageDataObjectManager(
$this,
'Images',
'Image'
);
$fields->addFieldToTab("Root.Content.Images",$images);
return $fields;
}
}class Website_Controller extends Page_Controller {
} -
Re: has-many images using imagedataobjectmanager

17 September 2010 at 12:10am
You need a $has_one at the Image as well.
I would extend Image and add the $has_one there:
class MyImage extends Image{
static $has_one = array(
'Website'
);}
class Website extends Page {
static $has_many = array(
'Images' => 'MyImage'
);}
-
Re: has-many images using imagedataobjectmanager

17 September 2010 at 2:40am Last edited: 17 September 2010 2:42am
That worked briliantly thank you very much.
Another little query I am stuck next with. On the homepage I want to display 5 of the latest Websites although the part I can't get to work is the previously relation for the portfolios
Currently I have:
<ul>
<% control LatestWebsites %>
<li>
<a href="$Link" title="Project title here">
<% control Portfolios %>
$Image
<% end_control %>
</a>
<h3><a href="$Link" title="Project title here">$Title</a></h3>
<p>$Content.LimitWordCountXML(30) <a href="$Link" title="Project title here">More...</a></p>
</li>
<% end_control %>
</ul>----- Page.php
// Latest Featured Websites
function LatestWebsites($num=10) {
return DataObject::get("Websites", "Featured = 1", "Completion DESC", "", $num);
}----- Homepage.php
<?php
class Homepage extends Page {
static $has_many = array('Slogans' => 'Slogans');public function getCMSFields(){
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Slogans", new DataObjectManager(
$this,
'Slogans',
'Slogans',
array(
'SloganText'=> 'Text',
'CSSid' => 'CSS ID',
'SloganImage' => 'Image',
'SloganBackground' => 'Background'
),
'getCMSFields_forPopup'
));
return $fields;
}
}
class Homepage_Controller extends Page_Controller {}----- Websites.php
class Websites extends Page {
static $db = array (
'Featured' => 'Boolean',
'Completion' => 'Date'
);
static $has_many = array('Portfolios' => 'Portfolios');
static $has_one = array('WebsitesBrowse' => 'WebsitesBrowse');
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->renameField('Title', 'Website Title');
$fields->addFieldToTab('Root.Content.Main', new CheckboxField(
$name = "Featured",
$title = "<strong>Featured Website</strong> - Check to display on the homepage"),
'Content');
$fields->addFieldToTab("Root.Content.Main", new DateField('Completion'));$images = new ImageDataObjectManager(
$this,
'Portfolios',
'Portfolios'
);
$fields->addFieldToTab("Root.Content.Portfolios",$images);
return $fields;
}
}
class Websites_Controller extends Page_Controller {}----- Portfolio.php
<?php
class Portfolios extends Image {
static $has_one = array(
'Websites' => 'Websites'
);
}
| 1428 Views | ||
|
Page:
1
|
Go to Top |


