Im learning doctrine and i have a form with ZF2 and doctrine with field "email".
This field need to be unique, so i need validator for it. Problem is, when i use:
DoctrineModule\Validator\UniqueObject
it is impossible to create new entity. This validator need primary key to compare.
Validator dump error with message:
Expected context to contain itemId
itemId is my primary key.
So its obvious, that i need to use UniqueObject for update, and:
DoctrineModule\Validator\NoObjectExists
for new entity. And question is:
What is the best way, to store different input filter specification for existing and new entity?
Or, better if possible: How to use Unique validator with new, and existing records with zend form fieldsets.
If i put it in the form, I need to modify it inside controller if entity is new or no. Not so good idea.
I think that the best way is to store input filter spec. inside entity repository, but how i can check there if entity is new or not?
---- edit
I saw documentation, i know how to use unique object but i have error like said before: "Expected context to contain itemId". I think problem is with fieldsets (im using it). I dont understand how to do this (text from docs):
If you leave out the use_context option or set it to false you have to
pass an array containing the fields- and identifier-values into
isValid(). When using Zend\Form this behaviour is needed if you're
using fieldsets.
Ok im using fieldsets, so now what i can do? How i can pass correct values to isValid when im using zend forms?
0 comments:
Post a Comment