Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

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

NewsArticle - > NewsArticle_Live and DataObjectAsPage -> DataObjectAsPage_Live!!

Go to End

3 Posts   1390 Views


Community Member, 14 Posts

1 June 2012 at 1:13am

Edited: 06/06/2012 12:10am

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
(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

Community Member, 14 Posts

4 June 2012 at 11:47pm

Edited: 06/06/2012 12:10am

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 !


Community Member, 14 Posts

11 June 2012 at 7:30pm