Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » DataObjects as Pages does not work :<

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: 588 Views
  • phokki
    Community Member
    14 Posts

    DataObjects as Pages does not work :< Link to this post

    Hello SilverStripe folks,

    I've got a newsarticle.php page and a newsarticleholder.php.

    This is my NewsArticle.php

    class NewsArticle extends DataObjectAsPage {
       //The class of the page which will list this DataObject
    static $listing_class = 'NewsArticleHolder';
    //Class Naming (optional but reccomended)
    static $plural_name = 'NewsArticles';
    static $singular_name = 'NewsArticle';

       static $db = array (
          'Title' => 'Varchar(255)',
          'Date' => 'Date',
       'Author' => 'Text',
       'Content' => 'HTMLText',
       static $has_one = array (
          'NewsHolder' => 'NewsArticleHolder',
       //Summar fields
    static $summary_fields = array(

       function fieldLabels($includerelations = true) {
        $labels = parent::fieldLabels($includerelations);
        $labels['Title'] = _t('newsarticle.TITLE', 'Titel');
        $labels['Date'] = _t('newsarticle.DATE', 'Datum');
        $labels['Author'] = _t('newsarticle.AUTHOR', 'Auteur');
        $labels['Content'] = _t('newsarticle.CONTENT', 'Niewsbericht');
        return $labels;
       function getCMSFields() {   
        $fields = new Fieldset();
        $fields->push(new TextField('Title','Titel'), 'Content');
        $fields->push($dateField = new DateField('Date','Datum'), 'Content');
        $dateField->setConfig('showcalendar', true);
        $dateField->setConfig('dateformat', 'dd/MM/YYYY');
        $fields->push(new TextField('Author','Auteur'), 'Content');
        $fields->push(new HtmlEditorField("Content", _t('SiteTree.FOO', "Content", PR_MEDIUM, 'HTML editor title')));

        return $fields;

    and this is my NewsArticleHolder.php


    class NewsArticleHolder extends DataObjectAsPageHolder {
       static $has_many = array (
           'NewsArticles' => 'NewsArticle',
       public function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldsToTab("Root.Content.Nieuws", new DataObjectManager($this, 'NewsArticles', 'NewsArticle'));
          return $fields;

    class NewsArticleHolder_Controller extends DataObjectAsPageHolder_Controller {
    //This needs to know be the Class of the DataObject you want this page to list
    static $item_class = 'NewsArticle';
    //Set the sort for the items (defaults to Created DESC)
    static $item_sort = 'Title ASC';


    So my CMS just works fine, can add newsitems but when im on the newspage,
    it wont show my newsitems

    This is my NewsArticleHolder.ss

    <div class="typography">
       <% if Level(2) %>
           <div class="breadcrumbs">
       <% end_if %>
       <div class="articles">
        <ul id="NewsList">             
             <% control NewsArticles %>
             <% end_control %>   

    Please help me guys!! I have no idea what i'm doing wrong, and im quite new to this....


  • Tim Snadden
    Community Member
    32 Posts

    Re: DataObjects as Pages does not work :< Link to this post

    If you are using the Data Objects as Pages module I believe the Controller method you need in the template is 'Items' for the listing page and 'Item' for the individual news article.

  • Tim Snadden
    Community Member
    32 Posts

    Re: DataObjects as Pages does not work :< Link to this post

    This article by the author of the module gives pretty good instructions on how to use it. http://www.ssbits.com/tutorials/2012/dataobject-as-pages-the-module/

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.