silverstripe对象 - > __ call():'HasMany List'上不存在'fortemplate'方法,或者方法不公开

问题描述 投票:2回答:1

我在前端模板中收到此错误我的模板文件为空,当我尝试addFieldToTab时。我认为$has_many变量有问题。

我的代码如下:

class ProductsPage extends Page
{
  private static $has_many = array (
    'ProductCategories' => 'ProductCategories',
  );

    public function getCMSFields() {
       $fields = parent::getCMSFields();
       $fields->addFieldToTab('Root.Main', GridField::create(
            'ProductCategories',
            'Category',
            $this->ProductCategories(),
            GridFieldConfig_RecordEditor::create()
        ));
       return $fields;
   }
}

错误:

[User Error] Uncaught Exception:Object - > __ call():'HasManyList'上不存在'fortemplate'方法,或者该方法不公开。

PasteBin URL:https://pastebin.com/YZJn3a4t

当我删除$has_many变量它工作完美。在我的前端模板是空的。

如何解决这个错误,我不明白?

php silverstripe has-many silverstripe-4
1个回答
0
投票

$ has_many数组值应该是单数形式,而它的关键是复数。

使用你的例子,这应该是'Category'=>'ProductCategories'(我从你在下面的GridField中做的那样得到了这个)。

希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.