Zend Framework 2 - Hydrator strategy not responding and hydrating

前端 未结 2 1175
时光说笑
时光说笑 2021-01-17 04:28

I implemented basically this strategy.

The main difference is (I guess) that I use Doctrine2.

The constructor class is called (a test echo is pr

相关标签:
2条回答
  • 2021-01-17 04:59

    @Sam solved this problem on GitHub.

    This is a problem that is commonly happening currently. The thing is: addStrategy() is a thing of ZF2's ClassMethodHydrator - this hydrator is used silently within DoctrineEntity. To add custom Strategies, simply do not use DoctrineEntity but use ClassMethodsHydrator itself. On ClassMethods then you'll be able to add Strategies

    You may also take a look at this Issue/PR doctrine/DoctrineModule#106

    My code now looks like this:

    $hydrator = new ClassMethodsHydrator();
    $hydrator->addStrategy('my_attribute', new MyHydrationStrategy());
    $form->setHydrator($hydrator);
    

    BTW: The underscore in the attribute doesn't cause any problems

    Unfortunately I stumbled upon another foreign-key-relation-based issue, it seems even a Doctrine issue. But I'll open a new question for this.

    0 讨论(0)
  • 2021-01-17 05:00

    Please refer to this post, for a cleaner and more appropriate solution!

    Zend Framework 2 - Hydrator strategy for Doctrine relationship not working

    0 讨论(0)
提交回复
热议问题