Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

SS3 : TreeDropdownField in DataObject [Resolved]


Go to End


3 Posts   1373 Views

Avatar
raspberrydesignsprl

Community Member, 2 Posts

25 October 2012 at 2:33am

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

Avatar
raspberrydesignsprl

Community Member, 2 Posts

25 October 2012 at 8:51pm

I resolved this problem.

In my template, the tag must be $getUrl.URLSegment

Avatar
Van

Administrator, 25 Posts

26 October 2012 at 7:17am

Glad to hear you solved your problem so quickly and thank you for sharing your conclusion with us.