Hi
try this
set you has one relationship in ProjectPage.php
class ProjectPage extends Page {
static $has_one = array(
'PortfolioPage' => 'PortfolioPage'
);
..............
PortfolioPage.php
static $has_many = array (
'Projects' => 'ProjectPage ',
);
public function getCMSFields() {
$f = parent::getCMSFields();
$tablefield = new HasManyComplexTableField(
$this,
'Projects',
'ProjectPage ',
array(
'Title' => 'Title',
),
'getCMSFields_forPopup'
);
$tablefield->setPermissions(array("show"));
$f->addFieldToTab( 'Root.Content.Projects', $tablefield );
return $f;
}
public function onBeforeWrite()
{
$beforePage = DataObject::get("ProjectPage ", 'PortfolioPage="1"' ');
if($beforePage)
{
foreach($beforePage as $page) {
$page->writeToStage('Stage');
$page->publish('Stage', 'Live');
$page->flushCache();
}
}
parent::onBeforeWrite();
}
tutorial here http://doc.silverstripe.org/doku.php?id=hasmanycomplextablefield
now your structure could be like this.
ProjectHolder
ProjectPage(1)
ProjectPage(2)
ProjectPage(3)
ProjectPage(x)
...
PortfolioHolder
PortfolioPage
in portfolio page you will have a HasManyComplexTableField showing all your project which are of page Type ProjectPage
In an portfolio just tick the projects you want to associate with that Portfolio you are in.
as for the image in you Project page under $has_many put this line
static $has_many = array (
'Images' => 'Resource',
);
protected static $_cached_pages = null;
public function getCMSFields() {
$f = parent::getCMSFields();
$fileMan = new ImageDataObjectManager(
$this,
'Images',
'Resource',
'Attachment',
array(
'Name' => 'Name',
'Caption' => 'Caption',
),
'getCMSFields_forPopup'
);
$fileMan->setAllowedFileTypes(array('jpg'));
$fileMan->setGridLabelField('Name');
$fileMan->setAddTitle('Images');
$f->addFieldToTab("Root.Content.Images", new HeaderField(
$title = "Images",
$headingLevel = "2"
));
$f->addFieldToTab("Root.Content.Images", $fileMan);
return $f;
}
Resource.php
<?php class Resource extends DataObject
{
static $db = array (
'Name' => 'Text',
'Caption' => 'Text',
);
static $has_one = array (
'Attachment' => 'Image',
'ProjectPage ' => 'ProjectPage ',
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Name'),
new TextareaField('Caption'),
new FileIFrameField('Attachment' , 'Image .. (Please don´t upload an image which is more than 1mb)')
);
}
}
?>
for the images tutorials here
http://doc.silverstripe.org/doku.php?id=modules:dataobjectmanager&s=resource%20php