Jump to:

23459 Posts in 18906 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » How to set up TableField

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: 1028 Views
  • klikhier
    Avatar
    Community Member
    150 Posts

    How to set up TableField Link to this post

    I would like to add a TableField to a tab in the CMS to simple add a list of hyperlinks (title + link) to a page. Problem: in my current setup when I change/add a hyperlink on a page, the change is reflected on all other pages as well. What should I change to prevent this from happening?

    //mysite/code/Hyperlink.php

    <?php

    class Hyperlink extends DataObject
    {
       static $db = array (
    'Title' => 'Text',
    'Link' => 'Text'
       );

       static $has_one = array (
          'CaseExamplePage' => 'CaseExamplePage'
       );

       public function getCMSFields_forPopup()
       {
          return new FieldSet(
    new TextField('Title'),
    new TextField('Link')
          );
       }

    }

    ?>

    //mysite/code/CaseExamplePage.php

    <?php
    class CaseExamplePage extends Page {

       public static $has_many = array(
    'Hyperlinks' => 'Hyperlink'
       );

       public function getCMSFields() {
          $fields = parent::getCMSFields();
          
          // Add Hyperlinks tab
          $tblf = new TableField(
             //$this,
             'Hyperlinks',
             'Hyperlink',
             array('Title' => 'Title', 'Link' => 'Link'),
             array('Title' => 'TextField', 'Link' => 'TextField'),
             null,
             "Hyperlink.CaseExamplePageID",
             $this->ID
          );
          $fields->addFieldToTab('Root.Content.Hyperlinks', $tblf);

    (...)

  • JonYYC
    Avatar
    Community Member
    10 Posts

    Re: How to set up TableField Link to this post

    Check the parameters of the TableField constructor. I think it should be:

    $tblf = new TableField(
    'Hyperlinks',
    'Hyperlink',
    array('Title' => 'Title', 'Link' => 'Link'),
    array('Title' => 'TextField', 'Link' => 'TextField'),
    "CaseExamplePageID",
    $this->ID
    );

    Jonathan.

    1028 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.