I couldn't find these two questions asked already, so here it goes:
First question: I'm following the second tutorial on SilverStripe, and have reached the section on adding database fields for specific Page Types - ArticlePage in this case. The examples in the tutorial use the fields $Date and $Author. Following the same pattern, I added my own field - $Level. While this $Level field appears in the CMS Content->Main tab for the relevant page, I cannot make the contents of the field print to the screen in my website - I just get a blank space. This is my ArticlePage.php (the comments relate to my second question):
<?php
class ArticlePage extends Page {
static $db = array(
'Date' => 'Date',
'Author' => 'Text',
'Level' => 'Text'
);
static $has_one = array(
);
/*$datefield = new DateField('Date');
$datefield->setConfig('showcalendar', true);
$datefield->setConfig('showdropdown', true);
$datefield->setConfig('dateformat', 'dd/MM/YYYY');*/
function getCMSFields() {
$fields = parent::getCMSFields();
//$fields->addFieldToTab('Root.Content.Main', $datefield, 'Content');
$fields->addFieldToTab('Root.Content.Main', new DateField('Date'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Level'), 'Content');
return $fields;
}
}
class ArticlePage_Controller extends Page_Controller {
}
?>
and here is my Layout/ArticlePage.ss:
<% if Menu(2) %>
<ul id="Menu2">
<% control Menu(2) %>
<li class="$LinkingMode"><a href="$Link" title="Go to the $Title page">$MenuTitle</a></li>
<% end_control %>
</ul>
<% end_if %>
<div id="Content" class="typography">
<% if Level(2) %>
<div class="breadcrumbs">
$Breadcrumbs
</div>
<% end_if %>
<h1>$Title</h1>
$Content
<div class="newsDetails">
$Date.Nice by $Author for $Level
</div>
</div>
My second question: the commented out sections in ArticlePage.php are what a comment (by 'Frank') in Tutorial 2 said to put in to allow the JavaScript Date Picker to be used to select a date. However, when I run this code, having removed the original date code, I get this error:
Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /home/irevise/public_html/mysite/code/ArticlePage.php on line 13
Line 13 is $datefield = new DateField('Date');.
However I shift code about, I always get this error.
Can anybody shed any light on either of these two issues?