[TYPO3-mvc] How to validate if input value is unique in table?
Uwe Michelfelder
um at limeflavour.com
Tue Feb 23 19:35:45 CET 2010
Hello Manuel,
thankks sharing your knowledge on this. I tried to do this on directly
in the Domain Model. Now I do it on the Controler Action, just like you
suggestet, and it works.
But one more question. How do you fill the error-Stack for the proporty
which I just validated, so the formfield shows the error class?
Greetings,
Uwe
Am 23.02.10 16:23, schrieb Manuel Simon:
> Hello Uwe,
>
> I assume, your way of using a custom validator is right. In one of my
> custom validators I've implemented a unique check like this:
>
> I search my Repository for values with
>
> $found = [...]->findByEmail($member->getEmail());
> $count = count($found).
>
> If $count is 0, everything is fine.
> If $count is 1, you should check if $found[0]->getUid() is not equal to
> $member->getUid().
> If $count is greater than 1, you may have a problem ;-)
>
> If you get one result from your repository and it's the same object as
> the object to be updated - everything is fine. If not - add an error to
> the validator and return false.
>
> Kind regards,
> Manuel
>
> Am 22.02.2010 14:57, schrieb Uwe Michelfelder:
>> Hi list,
>>
>> I want to validate that the given email is not already used in the
>> repository.
>>
>> How is this solved correctly?
>>
>> If I create a custom validator in the Domain Model checking against the
>> repository by using ->findbyEmail() it would work for the add function,
>> but not validate at updating the Object, because the repository finds
>> the currently updated Object itself.
>>
>> Any suggestions to solve this?
>>
>> Greetings,
>> Uwe
>
More information about the TYPO3-project-typo3v4mvc
mailing list