Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i inject a repository to CommandController

Tags:

typo3

extbase

I got a commandController like this (using TYPO3 6.1):

class MyCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController {
    /**
     * fileRepository
     *
     * @var \VENDOR\MyExt\Domain\Repository\FileRepository
     * @inject
     */
    protected $fileRepository;
}

but when i try cast

$this->fileRepository->findAll();

i get:

Fatal error: Call to a member function findAll() on a non-object in

looks like the repostory is not autoinjected with @inject like it is in ActionControllers.

How do i inject the repository manually?

like image 954
TomGrill Games Avatar asked Feb 21 '26 01:02

TomGrill Games


2 Answers

you can inject repositories in your commandcontroller. after adding a @inject in your doccomments you have to delete the cache and/or the cachefiles?

like image 112
freshp Avatar answered Feb 27 '26 02:02

freshp


Indeed, you need to clear the caches. Apparently in my case on Typo3 6.2 it only worked when I cleared the caches from the Install tool.

enter image description here

Note: I got this tip after reading a blog post on scripting-base.de (in German).

like image 32
Valentin Despa Avatar answered Feb 27 '26 02:02

Valentin Despa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!