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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Tutorial 2: Issues


Go to End


2 Posts   1440 Views

Avatar
Nath1011

Community Member, 2 Posts

14 March 2011 at 8:08pm

Ive been working through tutorial 2 and i can not get author and date fields to work can someone please help.

ArticlePage.php

<?php
/**
*Defines the ArticlePage page type
*/
class ArticlePage extends Page {
static $db = array(
'Date' => 'Date',
'Author' => 'Text'
);
static $has_one = array(
);
static $icon = "themes/tutorial/images/treeicons/news";
static $defaults = array(
'ProvideComments' => true
);
}

function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab('Root.Content.Main', $dateField = new DateField('Date','Article Date (for example: 20/12/2010)'), 'Content');
$datefield->setConfig('showCalendar', true);
$dateField->setConfig('dateformat', 'dd/MM/YYYY');

$fields->addFieldToTab('Root.Content.Main', new TextField('Author','Author Name'), 'Content');

return $feilds;
}

class ArticlePage_Controller extends Page_Controller {

}

?>

ArticlePage.ss

<% include Menu2 %>
<div id="Content" class="typography">
<% include Breadcrumbs %>
<h1>$Title</h1>
$Content
<div class="newsDetails">
Posted on $Date.Nice by $Author
</div>
$PageComments
</div>

ArticleHolder.php

<?php
/**
* Defines the ArticleHolder page type
*/
class ArticleHolder extends Page {
static $db = array(
);
static $has_one = array(
);
static $icon = "themes/tutorial/images/treeicons/news";
static $allowed_children = array('ArticlePage');
}

class ArticleHolder_Controller extends Page_Controller {
function rss() {
$rss = new RSSFeed($this->Children(), $this->Link(), "The coolest news around");
$rss->outputToBrowser();
}
function init() {
RSSFeed::linkToFeed($this->Link() . "rss");
parent::init();
}
}
?>

ArticleHolder.ss

<div id="Content" class="typography">
$Content
<ul id="NewsList">
<% control Children %>
<li class="newsDateTitle"><a href="$Link" title="Read more on &quot;{$Title}&quot;">$Title</a></li>
<li class="newsDateTitle">$Date.Nice</li>
<li class="newsSummary">$Content.FirstParagraph <a href="$Link" title="Read more on &quot;{$Title}&quot;">Read more &gt;&gt;</a></li>
<% end_control %>
</ul>
</div>

Avatar
digibrains

Community Member, 130 Posts

15 March 2011 at 5:04am

Can you describe what exactly isn't working? I.e., expected input, expected outcome.

I did notice this from looking at your ArticlePage.php file. You show:

<?php 
/** 
*Defines the ArticlePage page type 
*/ 
class ArticlePage extends Page { 
   static $db = array( 
      'Date' => 'Date', 
      'Author' => 'Text' 
      ); 
   static $has_one = array( 
      ); 
   static $icon = "themes/tutorial/images/treeicons/news"; 
   static $defaults = array( 
'ProvideComments' => true 
      ); 
}

   function getCMSFields() { 
      $fields = parent::getCMSFields(); 
       
      $fields->addFieldToTab('Root.Content.Main', $dateField = new DateField('Date','Article Date (for example: 20/12/2010)'), 'Content'); 
      $datefield->setConfig('showCalendar', true); 
      $dateField->setConfig('dateformat', 'dd/MM/YYYY'); 
       
      $fields->addFieldToTab('Root.Content.Main', new TextField('Author','Author Name'), 'Content'); 
       
      return $feilds; 
   } 
                                             

class ArticlePage_Controller extends Page_Controller { 
    
}

?>

Should be:

<?php 
/** 
 * Defines the ArticlePage page type 
 */

class ArticlePage extends Page { 
	static $db = array( 
		'Date' => 'Date', 
		'Author' => 'Text' 
	); 
	static $has_one = array( 
	); 
	static $icon = "themes/tutorial/images/treeicons/news"; 
	static $defaults = array( 
		'ProvideComments' => true 
	);


	function getCMSFields() { 
		$fields = parent::getCMSFields(); 
		$fields->addFieldToTab('Root.Content.Main', $dateField = new DateField('Date','Article Date (for example: 20/12/2010)'), 'Content'); 
		$datefield->setConfig('showCalendar', true); 
		$dateField->setConfig('dateformat', 'dd/MM/YYYY'); 
		$fields->addFieldToTab('Root.Content.Main', new TextField('Author','Author Name'), 'Content'); 
       
		return $feilds; 
	} 


}

   
                                             

class ArticlePage_Controller extends Page_Controller { 
    
}

Note, your getCMSField() function should be inside the class.