[TYPO3-mvc] Using repositories in validators
Matthew Colton
mat.colton at web-xs.de
Fri Dec 19 17:40:39 CET 2014
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!
--
Cheers
Matthew
More information about the TYPO3-project-typo3v4mvc
mailing list