The idea is that when adding a new Link the user will be able to select a LinkCategory from a DropdownField. This is to allow me to structure the template in a way that I can control each category and then each specific category's links.
Error Message:
[User Error] Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'LinkCategory'
GET /public_html/jonathandbaker/admin
Line 576 in D:\xampp\xampp\htdocs\public_html\jonathandbaker\sapphire\core\Object.php
LinkHolder.php
<?php
class LinkHolder extends Page {
static $singular_name = 'LinkHolder';
static $plural_name = 'LinkHolders';
static $db = array(
'Headline' => 'Text',
);
static $has_many = array(
'LinkCategories' => 'LinkCategory'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeFieldFromTab("Root.Content.Main", "Content");
$fields->addFieldToTab('Root.Content.Main', new TextField('Headline'));
$linksTable = new ComplexTableField(
$controller = $this,
$name = "Links",
$sourceClass = "Link",
$fieldList = array(
'LinkURI' => 'Link URI',
'LinkDisplayText' => 'Link Display Text',
'LinkCategory' => 'Link Category'
)
);
$fields->addFieldToTab('Root.Content.Links', $linksTable);
return $fields;
}
}
class LinkHolder_Controller extends Page_Controller {}
?>
LinkCategory.php
<?php
class LinkCategory extends DataObject {
static $db = array(
'LinkCategory' => 'Varchar(100)'
);
static $singular_name = 'LinkCategory';
static $plural_name = 'LinkCategories';
static $has_one = array(
'LinkHolder' => 'LinkHolder'
);
static $has_many = array(
'Links' => 'Link'
);
}
?>
Link.php
<?php
class Link extends LinkCategory {
static $db = array(
'LinkURI' => 'Text',
'LinkDisplayText' => 'Text',
);
static $singular_name = 'Link';
static $plural_name = 'Links';
static $has_one = array(
'LinkCategory' => 'LinkCategory'
);
public function getCMSFields(){
$categories = array(
'Mis Amigos' => 'Mis Amigos',
'jQuery' => 'jQuery',
'Blogs' => 'Blogs',
'Open-Source' => 'Open-Source',
'Design Inspiration' => 'Design Inspiration',
'Web Resources' => 'Web Resources'
);
$fields = new FieldSet(
new TextField('LinkURI', 'Link URI'),
new TextField('LinkDisplayText', 'Link Display Text'),
new DropdownField('LinkCategory','LinkCategory', $categories)
);
return $fields;
}
}
?>