dpd20130 2015-08-16 07:55
浏览 96

Doctrine orm:生成代理抛出“无法实例化自定义生成器”

Doctrine 2.5. When trying to generate proxies manually with

doctrine orm:generate-proxies

an exception is thrown:

[Doctrine\ORM\ORMException]
Can't instantiate custom generator : MyBundle\MyCustomGenerator

I have a custom generator defined which works correctly:

/**
 * @ORM\Column(type="string")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="CUSTOM")
 * @ORM\CustomIdGenerator(class="MyBundle\MyCustomGenerator")
 */
protected $id;

Also, instantiating the generator manually, like

$a = new MyBundle\MyCustomGenerator();

works. But for a reason the Doctrine Console throws the above exception.

I've tried to debug and check what's going on.
The exception is defined in completeIdGeneratorMapping of ClassMetadataFactory. I checked that $definition['class'] stores the name of my custom generator: MyBundle\MyCustomGenerator. But still, Doctrine can't find the class.
Thought I should add the definition to cli-config.php as explained in the doc, with use MyBundle or use MyBundle\MyCustomGenerator, but it did not work - still the same exception was thrown.

Any ideas how should I make the Doctrine Console aware of my custom ID generator?

  • 写回答

2条回答 默认 最新

  • dti3914 2016-06-09 11:31
    关注

    Not sure it will help or still need help, but try this

    @ORM\CustomIdGenerator(class="\MyBundle\MyCustomGenerator")

    ie add starting slash to class definition

    评论

报告相同问题?