0

我可以在管理页面中有 2 个网格域组件,其名称与同一个数据对象不同吗 - 例如

   class MainLandingPage_au extends Page
   {

    private static $has_many = [
       'ImagesWithHtml' => ImageWithHtml::class,
       'ImagesWithHtml2' => ImageWithHtml::class,
    ];

    // ...
    $fields->addFieldToTab('Root.Section1', HtmlEditorField::create('Section1Title','Section 1 Title')->setRows(4));
    $fields->addFieldToTab('Root.Section1', GridField::create(
        'ImagesWithHtml',
        'Images With Html For This Page',
        $this->ImagesWithHtml(),
        GridFieldConfig_RecordEditor::create()
    ));

    $fields->addFieldToTab('Root.Section2', HtmlEditorField::create('Section2Title','Section 2 Title')->setRows(4));
    $fields->addFieldToTab('Root.Section2', GridField::create(
        'ImagesWithHtml2',
        'Images With Html For Section 2',
        $this->ImagesWithHtml2(),
        GridFieldConfig_RecordEditor::create()
    ));
4

2 回答 2

0

你试过了吗?由于您有不同的关系,因此它应该可以正常工作。当然需要类has_one上的对应关系ImageWithHTML,见https://docs.silverstripe.org/en/4/developer_guides/model/relations/#has-many

所以你的代码应该是这样的:

   class MainLandingPage_au extends Page
   {

    private static $has_many = [
       'ImagesWithHtml' => `\Namespace\Of\ImageWithHtml.Foo`,
       'ImagesWithHtml2' => `\Namespace\Of\ImageWithHtml.Bar`
    ];

而在另一边

   class ImageWithHtml extends DataObject
   {

    private static $has_one = [
       'Foo' => MainLandingPage_au::class,
       'Bar' => MainLandingPage_au::class
    ];
于 2018-01-31T08:06:42.717 回答
0

是的,可以使用 2 个网格字段,这适用于正确的个人关系

class MainLandingPage_au extends Page
   {

    private static $has_many = [
       'ImagesWithHtml' => ImageWithHtml::class . '.AuMainLandingPage',
       'ImagesWithHtml2' => ImageWithHtml::class . '.AuMainLandingPage2'
    ];

    // ...
    // Gridfields as in posted question
    // ... etc

另一边

class ImageWithHtml extends DataObject
    {

    private static $has_one = [
       'AuMainLandingPage' => AuMainLandingPage::class . '.ImagesWithHtml',
       'AuMainLandingPage2' => AuMainLandingPage::class . '.ImagesWithHtml2'
    ];
于 2018-03-30T01:35:48.793 回答