0

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?

Yep_It's_Me
  • 4,494
  • 4
  • 43
  • 66
nyluje
  • 3,573
  • 7
  • 37
  • 67
  • That line where it crashes doesn't even look like the correct way to implement code. What are you trying to do? Do you have a reference tutorial or code that you are following? If so, can you post the link? I've seen a few of your posts on Symfony, and you seem to be following and older standard rather than [the latest documentation](https://symfony.com/doc/current/index.html). – Alvin Bunk Apr 05 '17 at 17:22
  • @Alvin Bunk, thank you for your input, I follow the SYMFONY documentation as much as I can. The work that has been made on this documentation is great. Maybe I use older standard there and there because I find solutions to my problems on SO or anywhere else. I won't go in the details of my final goal also I understand that knowing that could help you to guide me in other direction that could be relevant for me. But I am too advanced in my code, it works great in DEV mode, I just want it to work in PROD now. I cannot risk to redesign it all at that point. – nyluje Apr 06 '17 at 11:52

1 Answers1

0

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'];
             ....   
      }

}
nyluje
  • 3,573
  • 7
  • 37
  • 67