Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Help with displaying HasManyComplexTableField data on frontend

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: 723 Views
  • bronks
    Avatar
    Community Member
    2 Posts

    Help with displaying HasManyComplexTableField data on frontend Link to this post

    I'm trying to filter data objects to display on the front-end of my home page. I created three functions within my HomePage controller to filter categories. However nothing is displaying on the frontend. My code below:

    Resource.php:

    class Resource extends DataObject {
       static $db = array (
          'Name' => 'Text',
          'FileName' => 'Text',
          'Category' => "Enum('Program Details, Photograph Collections, Videos')"
       );
       public static $has_one = array(
          'MyPage' => 'HomePage'
       );

       public function getCMSFields_forPopup() {
          $fields = new FieldSet();
          $fields->push( new TextField( 'Name', 'Name' ) );
          $fields->push( new TextField( 'FileName', 'File Name' ) );
          $fields->push( new DropdownField('Category','Category', singleton('Resource')->dbObject('Category')->enumValues()) );
          return $fields;
       }

    Homepage.php:

    class HomePage extends Page {

       public static $db = array(
       );
       static $has_many = array (
          'Resources' => 'Resource'
       );
       
       function getCMSFields() {
          $fields = parent::getCMSFields();

          $tablefield = new HasManyComplexTableField(
             $this,
             'Resources',
             'Resource',
             array(
                'Name' => 'Name',
                'FileName' => 'File Name',
                'Category' => 'Category'
             ),
             'getCMSFields_forPopup'
          );
          $tablefield->setParentClass('HomePage');
          $tablefield->setAddTitle('A Resource');

          $fields->addFieldToTab( 'Root.Content.Resources', $tablefield );
          
          return $fields;
       }
    }
    class HomePage_Controller extends Page_Controller {

       public function ProgramDetails() {
          return $this->Level(1)->Resources("Category = 'Program Details'");
       }
       public function PhotographCollections() {
          return $this->Level(1)->Resources("Category = 'Photograph Collections'");
       }
       public function Videos() {
          return $this->Level(1)->Resources("Category = 'Videos'");
       }
    }

    Homepage.ss:

    <% if ProgramDetails %>
    <ul>
       <% control ProgramDetails %>
       <li>$Name</li>
       <% end_control %>
    </ul>
    <% end_if %>

    Help!!

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