In the past, I have done one to many or many to many relationship using hasmanycomplextablefield, ManyManyComplexTableField. However, is it possible to assign the same page type to itself to form a many to many relationship. For instance you create a page type named. 'Article page' then in its own class add many to many relationship.
<?php
/**
* Defines the ArticlePage page type
*/
class ArticlePage extends Page {
static $db = array(
'Headline' => 'Text',
'Summary' => 'Text'
);
static $has_one = array(
);
static $has_many = array(
'MyArticlePages' => 'ArticlePage',
'RelateToArticlePage' => 'ArticlePage'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TextField('Headline'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Summary'), 'Content');
$tablefield = new ManyManyComplexTableField(
$this,
'MyArticlePages',
'ArticlePage',
array(
'Headline' => 'Page Headline',
'Summary' => 'Summary'
),
'getCMSFields_forPopup',
null,
'Headline'
);
$tablefield->setAddTitle( 'A Related Page' );
$tablefield->setPermissions(array(
));
$fields->addFieldToTab( 'Root.Content.Related', $tablefield );
return $fields;
}
}
class ArticlePage_Controller extends Page_Controller {
}
?>
I got the following error:
Fatal error: Cannot instantiate abstract class Object in /var/www/vhosts/isnt-test.com/httpdocs/sapphire/core/Object.php on line 229
Has anyone done this before? thank you for taking the time to read this.