0
votes

Im creating new SilverStripe project based on the tutorial of SilverStripe.

After adding this code, the CMS field dont show and gives error.

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

// .....

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

    $dateField = new DateField('Date', 'Article Date (for example: 20/12/2010)');
    $dateField->setConfig('showcalendar', true);
    $dateField->setConfig('dateformat', 'dd/MM/YYYY');

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

    return $fields;
}

}

the error is:

Fatal error: Class 'DateField' not found in sample/sample/ line*

I don't see any problem with the code as I copy it from the tutorial itself. please help

1
Does your file have a namespace? Also, are you following SilverStripe 3 tutorials but in a SilverStripe 4 project? Can you share the contents of composer show in your terminal? - scrowler
either v3 and v4 gives the same error. - Urek Mazino
i mean both of them, no matter what code I copy gives the same error - Urek Mazino
4 would require a namespace, 3 should work. Can you provide more code to reproduce the problem? - scrowler
can you please explain about the namespace. im just new with the framework - Urek Mazino

1 Answers

0
votes

insert this at the top of ArticlePage.php:

use SilverStripe\Forms\DateField;