Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Displaying Dataobjects in a list on the frontend

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 578 Views
  • slavelabourer
    Avatar
    Community Member
    25 Posts

    Displaying Dataobjects in a list on the frontend Link to this post

    Hey guys, Having some trouble with a control block and complextablefield. Likely a n00b question but i'm at the point of wtf

    $category in the template will display a list of entries but i want to show all the fields from $category. My first time using the complextablefield, so i'm pretty stuck on whats going wrong here.

    cheers for you time

    DriverHolder.php

    <?php

    class DriverHolder extends Page {
    static $db = array(

    );

    static $has_one = array(

    );
    static $has_many = array(
       'category' => 'category'
    );

    function getCMSFields() {
       $fields = parent::getCMSFields();
       $fields->addFieldToTab('Root.Content.Drivers', new ComplexTableField(
          $this,
          'Title',
          'category',
          array('Title' => 'Title', 'Description' => 'Description'),
          'getCMSFields_forPopup'
       ));
       
       return $fields;

    }
    }

    class DriverHolder_Controller extends Page_Controller {}

    ?>

    DriverHolder.ss

    <table>
       <th>Driver</th><th>Description</th><th>Download</th>
          <% control catagory %>
             <tr>
             <td>$Title</td>
             <td>$Description</td>
             <td>$File.URL</td>
             </tr>
          <% end_control %>
    </table>

  • JonoM
    Avatar
    Community Member
    103 Posts

    Re: Displaying Dataobjects in a list on the frontend Link to this post

    You have a typo in your control block "catagory" - could be the cause?

  • slavelabourer
    Avatar
    Community Member
    25 Posts

    Re: Displaying Dataobjects in a list on the frontend Link to this post

    Yes i did, but i cleaned it up and still not working heres the cleaners version

    driver.php

    <?php
    class driver extends DataObject {

       static $db = array (
          'Title' => 'Text',
          'Description' => 'Text'   
       );
          
       static $has_one = array (
          'DriverHolder' => 'DriverHolder',
          'File' => 'File'    
       );
       
       static $has_many = array ();
       
       function getCMSFields_forPopup() {
          $fields = new FieldSet();
          $fields->push(new TextField('Title', 'Title'));
          $fields->push(new TextField('Description', 'Description'));
          $fields->push(new FileIFrameField('File', 'File'));
          
          return $fields;
       }
    }


    DriverHolder.php

    <?php
    class DriverHolder extends Page {
    static $db = array();

    static $has_one = array();

    static $has_many = array(
       'driver' => 'driver'
    );

    static $allowed_children = array('DriverPage');

    function getCMSFields() {
       $fields = parent::getCMSFields();
       $fields->addFieldToTab('Root.Content.drivers', new ComplexTableField(
        $this,
              'Title',
              'driver',
       array('Title' => 'Title'),
              'getCMSFields_forPopup'
       ));
       return $fields;
    }
    }

    class DriverHolder_Controller extends Page_Controller {}


    DriverHolder.ss

    <table width="100%">
       <th>Driver</th><th>Description</th><th>Download</th>
          <% control driver %>
             <tr>
              <td>$Title</td>
              <td>$Description</td>
                <td><a href="$File.URL">[download]</a></td>
             </tr>
          <% end_control %>
       </table>

          

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