Jump to:

10989 Posts in 2726 Topics by 1817 members

All other Modules

SilverStripe Forums » All other Modules » NewsArticle - > NewsArticle_Live and DataObjectAsPage -> DataObjectAsPage_Live!!

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 762 Views
  • phokki
    Community Member
    14 Posts

    NewsArticle - > NewsArticle_Live and DataObjectAsPage -> DataObjectAsPage_Live!! Link to this post

    Hello SilverStripers!

    I have got a newsarticlepage which show the latest news. The problem is, the news is only shown when i'm visiting the draft page and not the live page.

    I use the DataObjectAsPage Module http://www.ssbits.com/tutorials/2012/dataobject-as-pages-the-module/
    (i dont use the productadmin)..

    My files are: newsarticle.php and newsarticleholder.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',

    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['Status'] = _t('newsarticle.STATUS', 'Status');
        $labels['Content'] = _t('newsarticle.CONTENT', 'Niewsbericht');
        return $labels;
    //options for the new OptionsetField
    protected $options = array(
        'Published' => 'Yes',
        'Draft' => 'No'
       function getCMSFields() {

        $fields = new Fieldset();

          //Add the status/view link
             $color = '#E88F31';
             $links = '<a target="_blank" href="' . $this->Link('?stage=Stage') . '">Draft</a>';
             $status = $this->Status;
             if($this->Status == 'Published')
                $color = '#000';
                $links .= ' | <a target="_blank" href="' . $this->Link('?stage=Live') . '">Published</a>';
                   $status .= ' (changed)';
                   $color = '#428620';

             $fields->insertFirst(new LiteralField('',
                '<div class="doapToolbar">
                   <h3 class="doapTitle" style="background: '.$color.';">'. $status . '</h3>
                   <p class="doapViewLinks">
                      Page View:' . $links . '

        $fields->push(new TextField('Title','Titel'), 'Content');
        $fields->push($dateField = new DateField('Date','Datum'), 'Content');
        // $fields->push(new CheckboxField ('Status','Publish'),'Content') ;
        $fields->push(new OptionsetField(
        $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;



    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';


    The problem is:

    When i post a new newsarticle, it inserts it to DataObjectAsPage table
    but not in the DataObjectAsPage_Live table.....

    Same is for NewsArticle.. It inserts in NewsArticle table but not in NewsArticle_Live....

    I wanted to fix this by using a checkbox for Publishing or Drafting, this works but i dont know where to use

    Does anyone knows a way to fix this?
    I've got no solution yet...


    Attached Files
  • phokki
    Community Member
    14 Posts

    Re: NewsArticle - > NewsArticle_Live and DataObjectAsPage -> DataObjectAsPage_Live!! Link to this post

    Another question: is the doPublish() function the right function to insert my page into the dataobjectaspage_live table or is there an another function for it?

    And if i change the "article" to draft, i probably need doUnpublish() ?

    But the main question: how can i use those functions!!

    Thanks !

  • phokki
    Community Member
    14 Posts
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.