16/10/2013 1:18am

PHP | Problem -


<?php


/****************************************************************
* *
* ESTABLISH PARAMETERS FOR EACH NEWS ARTICLE *
* *
*****************************************************************/

class NewsArticle extends DataObject {


public static $db = array(
'SortOrder' => 'Int',
'Title' => 'Varchar',
'Category' => 'Int',
'Content' => 'HTMLText'
);

//One-to-one relationship with news page
public static $has_one = array('News' => 'News');

//Tidy up CMS by removing the fields we don't want users to modify.
public function getCMSFields() {
$fields = parent::getCMSFields();

//Remove Title field and readd it with a new title
$fields->removeFieldFromTab("Root.Main","Title");
$fields->addFieldToTab("Root.Main", new TextField("Title", "Article Name"), "Content");

//Add dropdown with category options
$dropdown = new DropdownField('Category','Article Category',Dataobject::get("NewsCategory")->map("ID", "Title"));
$dropdown->setEmptyString("(Select One)");
$fields->addFieldToTab("Root.Main", $dropdown, "Content");

//Remove fields that will confuse people
$fields->removeFieldFromTab("Root.Main","NewsID");
$fields->removeFieldFromTab("Root.Main","SortOrder");

return $fields;
}

//Set Required Fields
public function getCMSValidator() {
return new RequiredFields('Title');
}

// Tell the datagrid what fields to show in the table
public static $summary_fields = array('ID' => 'ID', 'Title' => 'Title', "Category" => "Category.Title");

}


Post Comment