[TYPO3-mvc] Using repositories in validators

g4-lisz at tonarchiv.ch g4-lisz at tonarchiv.ch
Fri Dec 19 19:16:50 CET 2014


Hi Matthew

I don't know if this helps, never tested it myself in a validator:

Maybe you should use the ObjectManager, like:

            $objectManager =
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
            $bemerkung =   
$this->objectManager->get('NS\Extname\Domain\Repository\ReservationRepository');

And: I dont't use double backslash in my methods for the object path...

Cheers,
Till

On 12/19/2014 05:40 PM, Matthew Colton wrote:
> Hi,
> I'm working on a system that includes ticketing.
>
> One problem I ran into is that the system has to check/validate if
> enough tickets are left to be able to complete the reservation process.
>
> So that's why I'm trying to use repositories in a validator. Injecting
> repositories doesn't seem to work in validators. If I
>
>   /**
>    * Reservation repository
>    *
>    * @var \NS\Extname\Domain\Repository\ReservationRepository
>    * @inject
>    */
>   protected $reservationRepository;
>
> and then try to use
>
> $this->reservationRepository->amountOfReserverationsOfEventDate();
>
> it results in the following PHP error:
>
> Fatal error: Call to a member function
> amountOfReserverationsOfEventDate() on a non-object in
> /var/www/laks/hessen-szene.de/cms/typo3conf/ext/laks/Classes/Validation/Validator/EnoughTicketsAvailableValidator.php
> on line 69
>
> If I try to make an instance manually via
>
> $this->reservationRepository =
> \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('NS\\Extname\\Domain\\Repository\\ReservationRepository');
>
> it results in the following exception:
>
> Argument 1 passed to
> TYPO3\CMS\Extbase\Persistence\Repository::__construct() must implement
> interface TYPO3\CMS\Extbase\Object\ObjectManagerInterface, none given,
> called in
> /var/www/typo3/typo3_src-6.2.9/typo3/sysext/core/Classes/Utility/GeneralUtility.php
> on line 4431 and defined in
> /var/www/typo3/typo3_src-6.2.9/typo3/sysext/extbase/Classes/Persistence/Repository.php
> line 75
>
> So what would be the correct approach?
>
> Thanks in advance!



More information about the TYPO3-project-typo3v4mvc mailing list