Hello
So, been spending a couple of days reading the lessons to try and see how to bend Silverstripe to accomplish what I want for my web site. I'm enjoying it a lot but I'm stuck trying to figure out the follow problem; the site will publish amateur short stories, so I have two DataObjects, one for Books and one for Chapters, since the chapters for the different books are released at different times.
I've made changes to the CMS for that and I have one created a new section BookAdmin, with two tabs; Books and Chapters respectively. All is fine; I can create new books in the Books tab and even list them in the Chapters tab, with one minor exception; when I fill the form on the Chapters tab, the data is not saved to the database.
Books are saved, but not chapters. I imagine that I could have the different AdminModel for the chapters as well but it just felt more natural to have the two, Books and Chapters in the same AdminModel.
Am I trying to do something that inherently cannot work or am I missing something?
I would appreciate more experienced eyes on this and will paste the code below.
Books.php
class Books extends DataObject
{
private static $db = array(
'Name' => 'Varchar',
'Tagline' => 'Varchar',
'Teaser' => 'Text'
);
private static $has_many = array(
'Chapter' => 'Chapters'
);
public function getCMSFields()
{
$fields = FieldList::create(TabSet::create('Root'));
$fields->AddFieldsToTab('Root.Books', TextField::create('Name'));
$fields->AddFieldsToTab('Root.Books', TextField::create('Tagline'));
$fields->AddFieldsToTab('Root.Books', TextareaField::create('Teaser', 'Short Description'));
$fields->AddFieldsToTab('Root.Chapters', Dropdownfield::create('BooksID','Books')
->setSource(Books::get()->map('ID','Name'))
->setEmptyString('-- Select a Book --')
);
$fields->AddFieldsToTab('Root.Chapters', TextField::create('Chapter Number', 'Chapter'));
$fields->AddFieldsToTab('Root.Chapters', DateField::create('Published', 'Publishing Date')->setConfig('showcalendar', true));
$fields->AddFieldsToTab('Root.Chapters', TextField::create('Author'));
$fields->AddFieldsToTab('Root.Chapters', TextareaField::create('Content', 'Story'));
return $fields;
}
}
Chapters.php
class Chapters extends DataObject
{
private static $db = array(
'Chapter Number' => 'Int',
'Content' => 'Text',
'Published' => 'Date',
'Author' => 'Varchar'
);
private static $has_one = array(
'Book' => 'Books'
);
}
BookAdmin.php
class BookAdmin extends ModelAdmin
{
private static $url_segment = 'books';
private static $menu_title = 'Books';
private static $managed_models = array(
'Books',
'Chapters'
);
}