【问题标题】:SilverStripe page create error Class 'DateField' not foundSilverStripe 页面创建错误类 'DateField' 未找到
【发布时间】:2023-04-04 07:03:01
【问题描述】:

我正在基于 SilverStripe 的 tutorial 创建新的 SilverStripe 项目。

添加此代码后,CMS 字段不显示并报错。

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;
}

}

错误是:

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

当我从教程本身复制代码时,我没有发现代码有任何问题。请帮忙

【问题讨论】:

  • 你的文件有命名空间吗?另外,您是否在关注 SilverStripe 3 教程但在 SilverStripe 4 项目中?可以在你的终端分享composer show的内容吗?
  • v3 和 v4 都会出现同样的错误。
  • 我的意思是他们两个,无论我复制什么代码都会给出相同的错误
  • 4 需要命名空间,3 应该可以工作。您能否提供更多代码来重现该问题?
  • 你能解释一下命名空间吗?我只是框架的新手

标签: php silverstripe


【解决方案1】:

ArticlePage.php的顶部插入这个:

use SilverStripe\Forms\DateField;

【讨论】:

    猜你喜欢
    • 2015-06-22
    • 1970-01-01
    • 2018-01-30
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    • 2016-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多