Hello,
I try to show the link of DataObject but I've an error :
[User Error] Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'Page'
My code :
class BlockHome extends DataObject
{
static $db = array (
'Title' => 'Varchar(255)',
'Description' => 'HTMLText',
'Link' => 'Int',
'Order' => 'Int'
);
static $has_one = array (
'Attachment' => 'Image',
'HomePage' => 'HomePage'
);
public static $summary_fields = array(
'Attachment.StripThumbnail' => '',
'Title' => 'Titre'
);
public function getCMSFields()
{
$thumbField = new UploadField('Attachment', 'Image');
$thumbField->allowedExtensions = array('jpg', 'png', 'gif');
return new FieldList(
new TextField('Title', 'Titre'),
new TextareaField('Description', 'Description'),
new TreeDropdownField('Link', 'Lien', 'SiteTree'),
$thumbField
);
}
public function getUrl()
{
if($this->Link)
{
$doSet = SiteTree::get()->byID($this->Link);
return $doSet ? $doSet : false;
}
return false;
}
}
class HomePage extends Page
{
static $icon = 'homepage/images/icon';
static $allowed_children = "none";
public static $has_many = array(
'Blocks' => 'BlockHome'
);
function getCMSFields()
{
$fields = parent::getCMSFields();
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldAddNewButton('toolbar-header-right'),
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(10),
new GridFieldEditButton(),
new GridFieldDeleteAction(),
new GridFieldDetailForm(),
new GridFieldSortableRows('Order')
);
$gridField = new GridField("Blocks", "Blocks :", $this->Blocks(), $gridFieldConfig);
$state = $gridField->State->GridFieldSortableHeader;
$state->SortColumn = 'Order';
$state->SortDirection = 'asc';
$fields->addFieldToTab("Root.Blocks", $gridField);
return $fields;
}
}
class HomePage_Controller extends Page_Controller
{
public function init()
{
parent::init();
Requirements::javascript("mysite/js/jquery.anythingslider.min.js");
Requirements::css('mysite/css/anythingslider.css');
}
}
My template :
<% if Blocks %>
<div id="extra">
<% loop Blocks %>
<a href="$getUrl" title="$Title">$Title</a>
...
<% end_loop %>
</div>
<% end_if %>
Can you help me ?
Thanks