Jump to:

23367 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » SS3 : TreeDropdownField in DataObject [Resolved]

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

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

Page: 1
Go to End
Author Topic: 643 Views
  • raspberrydesignsprl
    Avatar
    Community Member
    2 Posts

    SS3 : TreeDropdownField in DataObject [Resolved] Link to this post

    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

  • raspberrydesignsprl
    Avatar
    Community Member
    2 Posts

    Re: SS3 : TreeDropdownField in DataObject [Resolved] Link to this post

    I resolved this problem.

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

  • Van
    Avatar
    Administrator
    25 Posts

    Re: SS3 : TreeDropdownField in DataObject [Resolved] Link to this post

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

    643 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.