I have just started with Silverstripe and I am quite surprised how fast I could almost complete my website. Almost, because I got stuck in the last piece and after long hours of researching I have to confess that I can't make my way through it:
I am creating a website for my portfolio.
Therefore I have a
ProjectHolder Class extends Page // holder page to display summaries of all projects
ProjectPage Class extends Page // project page
ProjectCategories Class extends DataObject // contains different categories such as book design, wayfinding systems, etc.
Database relationships:
-----
ProjectPage:
public static $has_one = array(
'Category' => 'ProjectCategories' // every Project can have one Categoy
);
-----
ProjectCategories:
public static $has_many = array(
'Project' => 'ProjectPage' // every Category can contain many Projects
);
------
------
ProjectHolder
static $allowed_children = array('ProjectPage');
------
########
SO HERE IT COMES:
What I would like to do is to show a table in the CMS in the ProjectHolder Page to add/edit/delete my ProjectCategories. I would like to make it work with gridfields
Actually, I just can't work it out how to achieve this at all.
Your help will be very appreciated!
PS: Of course, I have read
http://doc.silverstripe.org/framework/en/tutorials/5-dataobject-relationship-management
But this doesn't help as I need the gridfield on the Holder Page
Probably I just need somebody pointing me in the right direction...
#########
Below are all Classes in detail:
class ProjectPage extends Page {
public static $db = array(
'Year' => 'Date',
'Title' => 'Varchar',
'Summary' => 'HTMLText'
);
public static $has_many = array(
'Photo' => 'Image'
);
public static $has_one = array(
'Category' => 'ProjectCategories'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$dateField = new DateField('Year');
$dateField->setConfig('showcalendar', true);
$dateField->setConfig('dateformat', 'YYYY');
$fields->addFieldToTab('Root.Main', $dateField, 'Content');
$fields->addFieldToTab('Root.Main', new TextField('Title'), 'Content');
$fields->addFieldToTab('Root.Main', new HtmlEditorField('Summary'), 'Content',5);
$fields->addFieldToTab("Root.Images", new UploadField('Photo'));
return $fields;
}
}
class ProjectCategories extends DataObject {
public static $db = array(
'Category' => 'Varchar'
);
public static $has_many = array(
'Project' => 'ProjectPage'
);
static $singular_name = 'Category';
static $plural_name = 'Categories';
}
class ProjectHolder extends Page {
static $allowed_children = array('ProjectPage');
public static $db = array(
);
public static $has_one = array(
);
}