M
M
Myroslav Zozulia2015-04-12 15:20:17
Zend Framework
Myroslav Zozulia, 2015-04-12 15:20:17

What is the best way to organize validation in ZF2?

Good day.
In a combat project, we use a bunch of zf2 + apigility. And now the situation is such that there is one endpoint that should validate and save data on PATCH requests. Save and validate depending on the data that comes in. That is, if this is a category, then we save the category, if the post is a post, etc. The zf-validation module is used. And here is just the problem, because by regular means you can install the so-called validators on the field. But I do not know in advance which object will come to me. I just can't get this module to work with custom validators.
Can anyone come across similar implementations and have ready-made developments? I would be very grateful, up to financial gratitude :)
Thanks for the answers.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Shirshov Alexander, 2015-04-16
@Keanor

In the resource itself:

$inputFilter = new SomeInputFilter();
$inputFilter->setData($params->toArray());

if (!$inputFilter->isValid()) {
    return new ApiProblem(50x, 'Params not valid');
}

More or less like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question