Jump to:

23455 Posts in 18904 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Tutorial 2 - SS 3.0.1 - dateField - crashing

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

Page: 1
Go to End
Author Topic: 498 Views
  • JohnCo
    Avatar
    Community Member
    5 Posts

    Tutorial 2 - SS 3.0.1 - dateField - crashing Link to this post

    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
  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: Tutorial 2 - SS 3.0.1 - dateField - crashing Link to this post

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

  • JohnCo
    Avatar
    Community Member
    5 Posts

    Re: Tutorial 2 - SS 3.0.1 - dateField - crashing Link to this post

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

    Kind regards,
    JohnCo.

    498 Views
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.