0

在 Ubuntu 服务器上的环境中运行我的 symfony3 项目,prod我收到以下错误:

"注意:未定义索引:data_collector/passed_options",

dev如果我使用环境,则不会发生此错误。

我的自定义中引发了错误FormType

// src/MyBundle/Form/CustomType/MyCustomType.php:
class MyCustomType extends AbstractType {
      public function buildForm(FormBuilderInterface $builder, array $options){
           $builder->addEventListener(FormEvents::POST_SET_DATA, function(FormEvent $event){....}
            $form = $event->getForm();
            $inheritedAttr = $form->getConfig()->getAttributes()['data_collector/passed_options']['attr']; //it crashes there
             ....   
      }

}

app_dev.php我在生产 Ubuntu 服务器上编辑了我的文件(就像这里解释的那样),以便我可以使用这个命令在生产中进行测试:

php bin/console server:start [我的服务器的IP]:[自定义端口]

但是错误仍然没有在dev环境中抛出。所以这不是我的开发机器的问题。

难道是环境$form->getConfig()->getAttributes()中没有索引prod

有什么方法可以调试在prod环境中发生但不在环境中发生的此类错误dev

4

1 回答 1

0

在作为参数传递的addEventListener函数中应该传递,因为它包含属性:$optionsbuildForm

class MyCustomType extends AbstractType {
      public function buildForm(FormBuilderInterface $builder, array $options){
           $builder->addEventListener(FormEvents::POST_SET_DATA, function(FormEvent $event) use ($options) {....}
            $form = $event->getForm();
            $inheritedAttr = $options['attr'];
             ....   
      }

}
于 2017-04-06T11:55:14.183 回答