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.

General Questions /

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

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

Tutorial 2 - SS 3.0.1 - dateField - crashing


Reply


3 Posts   530 Views

Avatar
JohnCo

Community Member, 5 Posts

9 August 2012 at 1:46pm

Edited: 09/08/2012 2:30pm

Following Tutorial 2: ArticlePage.php, causes a crash with:
"Fatal error: Call to a member function setConfig() on a non-object in C:\wamp\www\silverstripe\mysite\code\ArticlePage.php on line 12"

The code when adding the improving datefield instructions:

<?php
class ArticlePage extends Page {
static $db = array(
'Date' => 'Date',
'Author' => 'Text'
      );

public function getCMSFields() {

$fields = parent::getCMSFields();

      // JCo - Tutorial 2: Modifying Date field. Problem with the next line:
      // $fields->addFieldToTab('Root.Main', $dateField = new DateField('Date','Article Date (for example: 31/07/2012)'), 'Content');
// JCo - circumventing the problem....>

      $datefield = new DateField('Date','Article Date (for example: 31/07/2012)');
$datefield->setConfig('showcalendar', true);

      // Tutorial 2 - SS 3.0.1 - Next line causes crash
      // $dateField->setConfig('dateformat', 'dd-MM-YYYY');

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

return $fields;
}
}

class ArticlePage_Controller extends Page_Controller {
}

------------
What I'm doing wrong?
Kind regards, K=JohnC

Attached Files
Avatar
simon_w

Forum Moderator, 474 Posts

9 August 2012 at 3:23pm

Variables in PHP are case sensitive. You've defined $datefield, but are trying to call a method on $dateField.

Avatar
JohnCo

Community Member, 5 Posts

9 August 2012 at 4:11pm

Simon,
THANK YOU!...
I didn't catch that one. And of course, that explains the other line... :)

Kind regards,
JohnCo.