[FLOW3-general] validator-question
Robert Lemke
robert at typo3.org
Wed Feb 23 09:06:28 CET 2011
Hi Mathis,
Am 09.02.2011 um 00:21 schrieb Mathis Hoffmann:
> I have created a model "event" with the
> properties $begin (\DateTime) and $end (\DateTime). What I want to do
> now is to make shure that the begin-date ist before the end-date. Is
> it possible to solve that with a custom validator?
yes, you could write a validator as such:
namespace F3\MyPackage\Domain\Validator;
use F3\MyPackage\Domain\Model\Event;
class EventValidator implements \F3\FLOW3\Validation\Validator\ValidatorInterface {
public function isValid($value) {
if (!$value instanceof Event) {
return FALSE;
}
return ($value->getBegin() >= $value->getEnd());
}
...
}
> Therefore the validator needs access to the event-object.
yes
> How would you solve that, if the validator can't access its event-object?
In that case you can use Reflection, but I don't recommend that – it's better
to provide a getter for it. If you still want to use Reflection, there will
be a special support for it in the ObjectAccess class in FLOW3 1.0 beta 1.
But you can of course just use ReflectionProperty for it.
Cheers,
Robert
More information about the FLOW3-general
mailing list