我在前端模板中收到此错误我的模板文件为空,当我尝试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
变量它工作完美。在我的前端模板是空的。
如何解决这个错误,我不明白?
$ has_many数组值应该是单数形式,而它的关键是复数。
使用你的例子,这应该是'Category'=>'ProductCategories'(我从你在下面的GridField中做的那样得到了这个)。
希望这可以帮助。