Validating DateTime with NoObjectFound in Zend Doctrine #4949

Closed
opened 2026-01-22 14:53:57 +01:00 by admin · 4 comments
Owner

Originally created by @adarshkhatri on GitHub (Dec 26, 2015).

Originally assigned to: @Ocramius on GitHub.

I am trying to validate my datetime in zend but no luck so far.

This is my function:

private function addHolidayFilter()
    {
        $entityManager = $this->getEntityManager();

        ////////allocatedate is datetime type in db
        $this->form->getInputFilter()->get('allocatedate')->getValidatorChain()->attach(
            new NoObjectExistsValidator(array(
                'object_repository' => $entityManager->getRepository('Holiday\Entity\Holiday'),
                'fields'            => array('holidaydate'), ///////holidaydate is also datetime type in db
                'messages' => array(
                    'objectFound' => $this->getTranslatorHelper()->translate('You cannot choose this date. It is holiday.'),
                ),
            ))
        );
    }

What I am trying to achieve?

I have got a holiday in my table 1 and while adding data to table 2, I would like to check if chosen date exist in table 1.

If exist, throw custom message, else call add controller function.

However this is throwing me this message:

Fatal error: Call to a member function format() on string in
/Applications/XAMPP/xamppfiles/htdocs/skeleton/vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/DateTimeType.php
on line 53

I am not sure if this is the right place to ask this qst. And this might not be a issue at all.
I had asked this qst in stackoverflow as well: http://stackoverflow.com/questions/34435198/validating-datetime-in-zend-doctrine

Originally created by @adarshkhatri on GitHub (Dec 26, 2015). Originally assigned to: @Ocramius on GitHub. I am trying to validate my datetime in zend but no luck so far. This is my function: ``` private function addHolidayFilter() { $entityManager = $this->getEntityManager(); ////////allocatedate is datetime type in db $this->form->getInputFilter()->get('allocatedate')->getValidatorChain()->attach( new NoObjectExistsValidator(array( 'object_repository' => $entityManager->getRepository('Holiday\Entity\Holiday'), 'fields' => array('holidaydate'), ///////holidaydate is also datetime type in db 'messages' => array( 'objectFound' => $this->getTranslatorHelper()->translate('You cannot choose this date. It is holiday.'), ), )) ); } ``` **What I am trying to achieve?** I have got a holiday in my `table 1` and while adding data to `table 2`, I would like to check if chosen date exist in `table 1`. If exist, throw custom message, else call add controller function. However this is throwing me this message: > Fatal error: Call to a member function format() on string in > /Applications/XAMPP/xamppfiles/htdocs/skeleton/vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/DateTimeType.php > on line 53 **I am not sure if this is the right place to ask this qst. And this might not be a issue at all.** I had asked this qst in stackoverflow as well: http://stackoverflow.com/questions/34435198/validating-datetime-in-zend-doctrine
admin added the Invalid label 2026-01-22 14:53:57 +01:00
admin closed this issue 2026-01-22 14:53:59 +01:00
Author
Owner

@Ocramius commented on GitHub (Dec 26, 2015):

The information you supplied is incomplete: what is the stack trace for
that error?
Also, I'm not sure if you can use the NoObjectExistsValidator, as it will
use strict comparison internally (if I remember correctly)

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

On 26 December 2015 at 11:13, Adarsh Khatri notifications@github.com
wrote:

I am trying to validate my datetime in zend but no luck so far

This is my function:

private function addHolidayFilter()
{
$entityManager = $this->getEntityManager();

    ////////allocatedate is datetime type in db
    $this->form->getInputFilter()->get('allocatedate')->getValidatorChain()->attach(
        new NoObjectExistsValidator(array(
            'object_repository' => $entityManager->getRepository('Holiday\Entity\Holiday'),
            'fields'            => array('holidaydate'), ///////holidaydate is also datetime type in db
            'messages' => array(
                'objectFound' => $this->getTranslatorHelper()->translate('You cannot choose this date It is holiday'),
            ),
        ))
    );
}

What I am trying to achieve?

I have got a holiday in my table 1 and while adding data to table 2, I
would like to check if chosen date exist in table 1

If exist, throw custom message, else call add controller function

However this is throwing me this message:

Fatal error: Call to a member function format() on string in

/Applications/XAMPP/xamppfiles/htdocs/skeleton/vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/DateTimeTypephp
on line 53

I am not sure if this is the right place to ask this qst And this might
not be a issue at all

I had asked this qst in stackoverflow as well:
http://stackoverflowcom/questions/34435198/validating-datetime-in-zend-doctrine


Reply to this email directly or view it on GitHub
https://github.com/doctrine/doctrine2/issues/5574.

@Ocramius commented on GitHub (Dec 26, 2015): The information you supplied is incomplete: what is the stack trace for that error? Also, I'm not sure if you can use the NoObjectExistsValidator, as it will use strict comparison internally (if I remember correctly) Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On 26 December 2015 at 11:13, Adarsh Khatri notifications@github.com wrote: > I am trying to validate my datetime in zend but no luck so far > > This is my function: > > private function addHolidayFilter() > { > $entityManager = $this->getEntityManager(); > > ``` > ////////allocatedate is datetime type in db > $this->form->getInputFilter()->get('allocatedate')->getValidatorChain()->attach( > new NoObjectExistsValidator(array( > 'object_repository' => $entityManager->getRepository('Holiday\Entity\Holiday'), > 'fields' => array('holidaydate'), ///////holidaydate is also datetime type in db > 'messages' => array( > 'objectFound' => $this->getTranslatorHelper()->translate('You cannot choose this date It is holiday'), > ), > )) > ); > } > ``` > > _What I am trying to achieve?_ > > I have got a holiday in my table 1 and while adding data to table 2, I > would like to check if chosen date exist in table 1 > > If exist, throw custom message, else call add controller function > > However this is throwing me this message: > > Fatal error: Call to a member function format() on string in > > /Applications/XAMPP/xamppfiles/htdocs/skeleton/vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/DateTimeTypephp > on line 53 > > _I am not sure if this is the right place to ask this qst And this might > not be a issue at all_ > I had asked this qst in stackoverflow as well: > http://stackoverflowcom/questions/34435198/validating-datetime-in-zend-doctrine > > — > Reply to this email directly or view it on GitHub > https://github.com/doctrine/doctrine2/issues/5574.
Author
Owner

@adarshkhatri commented on GitHub (Dec 26, 2015):

Thank you for quick reply.

That's all the error message I am receiving, it's fatal error.

Scenario
I believe when this looks Holiday/Entity/Holiday entity table for datetime, it returns data as string, not an object, and format() function is called in doctrine/dbal/lib/Doctrine/DBAL/Types/DateTimeType.php on line 53 needs obviously object.

I can confirm that I need to compare strictly with the holiday so that I will not allow users to choose that date.

Is there any other way to achieve this in Doctrine/ZF2?

@adarshkhatri commented on GitHub (Dec 26, 2015): Thank you for quick reply. That's all the error message I am receiving, it's fatal error. **Scenario** I believe when this looks `Holiday/Entity/Holiday` entity table for datetime, it returns data as string, not an object, and `format()` function is called in `doctrine/dbal/lib/Doctrine/DBAL/Types/DateTimeType.php on line 53` needs obviously object. I can confirm that I need to compare strictly with the holiday so that I will not allow users to choose that date. Is there any other way to achieve this in Doctrine/ZF2?
Author
Owner

@Ocramius commented on GitHub (Dec 26, 2015):

Hi,

On 26 December 2015 at 12:04, Adarsh Khatri notifications@github.com
wrote:

I believe when this looks for Holiday/Entity/Holiday entity table for
datetime, it returns data as string, not an object, and format() function
is called in doctrine/dbal/lib/Doctrine/DBAL/Types/DateTimeType.php

Believing won't bring you anywhere: please get the complete stack trace.

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

@Ocramius commented on GitHub (Dec 26, 2015): Hi, On 26 December 2015 at 12:04, Adarsh Khatri notifications@github.com wrote: > I believe when this looks for Holiday/Entity/Holiday entity table for > datetime, it returns data as string, not an object, and format() function > is called in doctrine/dbal/lib/Doctrine/DBAL/Types/DateTimeType.php Believing won't bring you anywhere: please get the complete stack trace. Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/
Author
Owner

@Ocramius commented on GitHub (Dec 26, 2015):

Also, just realized that this is not an issue, therefore closing here: please ask for further help on the stackoverflow question that you linked above.

@Ocramius commented on GitHub (Dec 26, 2015): Also, just realized that this is not an issue, therefore closing here: please ask for further help on the stackoverflow question that you linked above.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4949