dennisg
dennisg

Reputation: 365

Doctrine 2.1 abstract entity, validation using annotations

My name is Denis and I really need your help or advice or anything :)

I am developing my project in Zend Framework 1.11 and am using Doctrine 2.1. I have successfully integrated Doctrine in my ZF project and everything works. I also integrated Gedmo extensions and some my custom extensions.

The problem is with validation. I want to have validation of doctrine entities by using annotations. Because I sometimes need to validate my entities sometimes don't, I want that sort of validation, for example: $user = new Entity\User; $user->setName('user'); $user->validate();

I don't want to change doctrine generated entities at all, so I won't change setters or use doctrine events for this.@HasLifecycleCallbacks. I run into example at http://www.spiffyjr.me/2011/07/15/more-doctrine-2-and-zend-framework-integration-goodies/.
I downloaded code but didn't managed to put it in work. I followed instructions from that page, made my entities extend AbstractEntity, but when try to use for example isValid() i recieve following error:
[Semantical Error] The annotation "@Column" in property Bild\Entity\TestTest::$id was never imported. Did you maybe forget to add a "use" statement for this annotation?

I use doctrine annotations without @ORM\, just @, (for example @Column, not @ORM\Column). I even tried to add ORM but no luck it continues to throw errors.

I can recieve metadata for my entity, get field mappings and associating mappings, but when I try to getPropertyAnnotation // validator annotations $vAnnotations = self::_getPropertyAnnotation($property, self::ZENDVALIDATION); var_dump($vAnnotations);die; I recieve mentioned semantic error.

I tracked the errors down to Doctrine\Common\Annotations\AnnotationReader::getPropertyAnnotations($property); not returning annotations but throwing errors. What do you think it can be?

It seems like I am not doing something properly but can't figure out what.

So, I need to make abstract entity, make my entities extend it, and make functions to validate my entities by using annotations.

So please, help me with this, if you can. I really need for my project but couldn't find a solution.

Thanks in advance. Best regards.

Upvotes: 2

Views: 1288

Answers (1)

Stephen Senkomago Musoke
Stephen Senkomago Musoke

Reputation: 3523

The problem is caused by the configuration of the annotation reader. I went through the same problems while integrating the Symfony2 validator service for my Doctrine2 models in ZF1, more on the blog post here http://ssmusoke.wordpress.com/2012/03/04/doctrine-2-day-2-model-validation-using-symfony-validator-service-in-zend-framework/

Upvotes: 0

Related Questions