Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php silverstrip对象->__call():方法';fortemplate&x27;不存在于';HasManyList';,或者该方法不是公共的_Php_Silverstripe_Has Many_Silverstripe 4 - Fatal编程技术网

Php silverstrip对象->__call():方法';fortemplate&x27;不存在于';HasManyList';,或者该方法不是公共的

Php silverstrip对象->__call():方法';fortemplate&x27;不存在于';HasManyList';,或者该方法不是公共的,php,silverstripe,has-many,silverstripe-4,Php,Silverstripe,Has Many,Silverstripe 4,我在前端模板中遇到此错误我的模板文件为空, 当我尝试addFieldToTab时。我认为,$有很多变量有问题 我的代码如下: class ProductsPage extends Page { private static $has_many = array ( 'ProductCategories' => 'ProductCategories', ); public function getCMSFields() { $fields = paren

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

我的代码如下:

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;
   }
}
错误:

[用户错误]未捕获异常:对象->\u调用():方法 “HasManyList”上不存在“fortemplate”,或者该方法不存在 公众

粘贴库URL:

当我删除
$has\u许多
变量时,它工作得非常好。在我的前端模板是空的

我不明白如何修复这个错误?

这个$has\u many数组值应该是单数形式,而它的键是复数形式

使用您的示例,这应该是'Category'=>'ProductCategories'(我是从您使用下面的GridField所做的工作中得到的)


希望这能有所帮助。

谢谢,我更改了$has\u许多数组键名,这很有效。”类别“=>”ProductCategories。有一个关于如何声明关系的实际定义。中的“关系是通过类上的静态数组定义构建的,格式为=>”。例如,值引用实际类