We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Model - customValidator: EntityInterface $model

I cannot see how can i make $model->field object request to be more customizable:

    class DbBetweenValidator extends Validator implements ValidatorInterface
    {
        public function validate(EntityInterface $model)
        {
            $field = $this->getOption('field');

            $newStart   = $this->getOption('startTime');
            $newEnd   = $this->getOption('endTime');

            $value = $model->$field;

The field is an event time and there can be multiple events for a particular day. So i would like to get all event times for a distinct date. Is it possible to do it with object model or i need to use phql or something like that?

Thank you.

What you want to achieve ? If the events are just some related field in day then you can juast access htis field.

edited Apr '16

You can pass whole model in validator options and do what you want with it, but its good from v 2.1, where the model validation is deprecated, UniquenessValidator is using it

    new DbBetweenValidator(
        array(
            "model" => $this,
            ...
        )
    );


14.9k

I want to create one validation class, that will gather all events(their times) for a particular day and compare the new event time with the old ones, to make sure there is no collision between them.

What you want to achieve ? If the events are just some related field in day then you can juast access htis field.



9.3k
Accepted
answer

Use phql to query events which are not the same event as current and have times between interval startTime and endTime. All necessary info you can gather from $model.



14.9k

Yes, this is what i have done exactly. Thank you.