dongxizhe9755 2017-04-05 16:42
浏览 47
已采纳

在PROD模式下抛出错误但不在DEV模式下抛出:$ notice-> getConfig() - > getAttributes()中的“注意:未定义的索引”

Running my symfony3 project in the prod enviroment on an Ubuntu Server I get the following error:

"Notice: Undefined index: data_collector/passed_options",

This error does not happen if I use the dev environment.

The error is thrown in my custom 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
             ....   
      }

}

I edited my app_dev.php file on the production Ubuntu Server (Like it is explained here) so that I could test in production using this command:

php bin/console server:start [the IP of my server]:[a custom port]

But the error still didn't get thrown in the dev environment. So it's not a problem with my development machine.

Could it be that $form->getConfig()->getAttributes() has no index in the prod environment?

Is there some way I can debug errors like this that happen in the prod environment but not in the dev environment?

  • 写回答

1条回答 默认 最新

  • dongzhang7382 2017-04-06 11:55
    关注

    In the addEventListener the $options that is passed as a parameter in the buildForm function should be passed as it contains the attributes:

    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'];
                 ....   
          }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上