Thanks CodeGuerrilla,
That method makes a lot of sense. However, I am having a few problems with the code you posted.
I decided to hard code my categories into the database, as they will rarely change.
As such my ArticleCategory.php page looks like this (and I think this page is my problem):
class ArticleCategory extends DataObject {
static $db = array(
'Category' => "Enum('News,Events,Press Releases,Events,Speeches')"
);
}
And I am adding the field to the CMS in ArticlePage.php like this:
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new DropdownField(
'Category',
'Category',
singleton('ArticleCategory')->dbObject('Category')->enumValues()
), 'Content');
return $fields;
Now what happens, is when I add/edit a news article, I can see the dropdown for category, and select one, but when I save it and come back, the category is reset to "News".
Nor will any of the categories show up in the form's select box on ArticleHolder.ss template, when I view it in the browser.
The whole ArticlePage.php page:
class ArticlePage extends Page {
static $db = array(
'Date' => 'Date',
'Author' => 'Text',
'Source' => 'Text'
);
static $has_one = array(
'FileUpload' => 'File',
'ArticleCategory' => 'ArticleCategory'
);
static $defaults = array(
'ShowInMenus' => false //do not show these pages in the main menu structure
);
static $can_be_root = false; //These pages can not be at the root level
static $allowed_children = "none"; //articles can not have sub pages
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeFieldFromTab("Root.Content.Main","HeaderImage"); //No header image upload
$fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Source'), 'Content');
$fields->addFieldToTab("Root.Content.Main", new DropdownField(
'Category',
'Category',
singleton('ArticleCategory')->dbObject('Category')->enumValues()
), 'Content');
$fields->addFieldToTab("Root.Content.Main", new FileIFrameField('FileUpload', 'Upload and Attach Document'), 'Content');
return $fields;
}
}
class ArticlePage_Controller extends Page_Controller {
}
Also, I am going to need to be able to link to the different "sorted" sections via a menu. Will I be able to link to a page like articles/news using the method you posted?