php - 无法将自定义站点配置添加到 Silverstripe 4

标签 php yaml silverstripe silverstripe-4

我正在关注 original docs但是 /dev/build 没有生成数据库字段,也没有生成表单字段。

这是我的 app/_config/app.yml

的值
---
Name: myproject
---
SilverStripe\Core\Manifest\ModuleManifest:
  project: app
---
Silverstripe\SiteConfig\SiteConfig:
  extensions:
    - CustomSiteConfig
---
SilverStripe\Admin\LeftAndMain:
  extra_requirements_css:
    - public/resources/admin/css/custom.css

这是我的app/src/extensions/CustomSiteConfig.php

<?php

use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\ORM\DataExtension;

class CustomSiteConfig extends DataExtension
{

    private static $db = [
        'FooterContent' => 'HTMLText'
    ];

    public function updateCMSFields(FieldList $fields)
    {
        $fields->addFieldToTab("Root.Main",
            new HTMLEditorField("FooterContent", "Footer Content")
        );
    }
}

Silverstripe 对我来说是新的,也许我在这里遗漏了一些东西。但我现在正在寻找一个小时,但无法让它发挥作用。

最佳答案

我认为问题在于您构建 YAML 的方式:

---
Name: myproject
---
SilverStripe\Core\Manifest\ModuleManifest:
  project: app
---
Silverstripe\SiteConfig\SiteConfig:
  extensions:
    - CustomSiteConfig
---
SilverStripe\Admin\LeftAndMain:
  extra_requirements_css:
    - public/resources/admin/css/custom.css

--- block 表示配置的每个部分的标题 block ,因此您在其中包含 Name: myproject 的部分之后使用的分隔线正在创建更多标题 block 将不再被视为配置。

试试这个:

---
Name: myproject
---
SilverStripe\Core\Manifest\ModuleManifest:
  project: app

Silverstripe\SiteConfig\SiteConfig:
  extensions:
    - CustomSiteConfig

SilverStripe\Admin\LeftAndMain:
  extra_requirements_css:
    - public/resources/admin/css/custom.css

关于php - 无法将自定义站点配置添加到 Silverstripe 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51468970/

相关文章:

azure - 如何在 Kubernetes Yaml 文件中将 pod 限制取消设置为无限制?

security - SilverStripe 3.1.x https - 是否有用于为共享 SSL 设置安全基本 URL 的配置选项?

php - 为什么 isset() 和 empty() 使用相同的操作码?

java - PHP Web 应用程序调用 Java 应用程序

javascript - 如何通过javascript更改textContent?

yaml - 如何在 Jekyll/Liquid 中获取哈希的键和值?

php - 如何在php中只显示第一张图片

yaml - 在 Ansible-YAML 中使用相对路径引用多维数组中的另一个元素

silverstripe - 在 cms 中限制语言

php - 如何自动删除 Silverstripe 中的空 [sitetree_link,id=] 标签?