如何通过SilverStripe 4中的Model Admin发布页面?

时间:2018-03-07 01:37:49

标签: silverstripe silverstripe-4

我已经创建了下面给出的Page,Data Object和Model Admin。

网页     

class MyPage extends Page {

  private static $db = [];
  private static $singular_name = "My Page";
  private static $plural_name = "My Pages";
  private static $description = 'A page created for testing';
}

数据对象     

use SilverStripe\ORM\DataObject;

class MyDataObject extends DataObject {

  private static $db = [
    'Test' => 'Int'
  ];
}

模特管理员

<?php

use SilverStripe\Admin\ModelAdmin;

class MyAdmin extends ModelAdmin  {

    private static $managed_models = [
        'MyPage',
        'MyDataObject'
    ];

    private static $url_segment = 'my-pages';
    private static $menu_title = 'My Page Admin';
}

当我创建一个新的&#34; MyDataObject&#34;单击保存按钮时,它会创建并发布对象。但是当我创建一个&#34; MyPage&#34;单击保存按钮后它仍然是草稿。我必须从Pages Tree打开页面并点击Publish按钮发布页面。

2 个答案:

答案 0 :(得分:2)

默认情况下,页面是版本化的,数据对象不是。

https://docs.silverstripe.org/en/4/developer_guides/model/versioning/

答案 1 :(得分:2)

您必须更改页面的代码,如下所示。 (只需添加此行 -  private static $ versioned_gridfield_extensions = true; )

<?php

class MyPage extends Page {

  private static $versioned_gridfield_extensions = true;

  private static $db = [];
  private static $singular_name = "My Page";
  private static $plural_name = "My Pages";
  private static $description = 'A page created for testing';

}