SilverStripe many_many_extrafields配置错误

时间:2018-04-12 11:37:37

标签: php silverstripe silverstripe-4

我在项目中设置many_many_extraFields之后某些DataObjects之间的<?php // Definizione Namespace use SilverStripe\ORM\DataObject; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\TextField; use SilverStripe\Forms\NumericField; use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; use SilverStripe\Forms\RequiredFields; use SilverStripe\Security\Permission; /** * Classe Sconto catalogo e prodotto */ class Sconto extends DataObject { [...] private static $many_many = [ 'Regole' => 'Regola' ]; private static $many_many_extraFields = [ 'Regole' => [ 'Area' => 'Varchar', 'Tipologia' => 'Varchar', 'Prezzo' => 'Currency' ] ]; [...] /** * Metodo gestione campi CMS * Setter * @return FieldList $fields Campi Back-End */ public function getCMSfields() { $fields = parent::getCMSFields(); [...] // Fetching campi Regole $regolaFields = singleton('Regola')->getCMSfields(); // Aggiunta campi specifici Regole $regolaFields->addFieldsToTab('Root.Regola', array( DropdownField::create('ManyMany[Area]', 'Area di applicazione', array( 'Prodotto' => 'Prodotto' ))->setEmptyString('Applica a'), DropdownField::create('ManyMany[Tipologia]', 'Criterio di applicazione', array( 'Prezzo' => 'Prezzo' ))->setEmptyString('Applica per'), NumericField::create('ManyMany[Prezzo]', 'Prezzo prodotto (€)')->setScale(2)->setAttribute('placeholder', 'Es. 5,00') ), 'Criterio'); $configRegole = GridFieldConfig_RelationEditor::create(); $configRegole->getComponentByType('GridFieldDetailForm')->setFields($regolaFields); $gridRegole = GridField::create('Regole', 'Regole', $this->Regole(), $configRegole); $fields->findOrMakeTab('Root.Sconto')->replaceField('Regole', $gridRegole); [...] return $fields; } } 关系。

使用以下代码:

$configRegole->getComponentByType('GridFieldDetailForm')->setFields($regolaFields);

framweork抛出这个例外:

  

[Alert]在null

上调用成员函数setFields()

参考这一行:

{col:df[col].dropna().to_dict() for col in df}

正如您所看到的,我在其之前添加了规范实例化 - 例如开发人员指南建议。

我正在试图弄清楚原因是什么,但我确信缺少某些东西。

提前致谢。

1 个答案:

答案 0 :(得分:2)

您需要使用其完全限定的类名引用GridFieldComponent类。这也适用于SS4中的任何类,如果您养成使用::class引用它们的习惯,则更容易使用,例如: Regola::class即使他们没有自己的命名空间。

正确的代码:

use SilverStripe\Forms\GridField\GridFieldDetailForm;
// ...
$configRegole->getComponentByType(GridFieldDetailForm::class)->setFields($regolaFields);