Is it possible to call a function in different controllers? I need to call FindByCategoryGrouped($catId)
in designRepository.php and getCategories($catId)
from categoryRepository.php
public function listAction() {
$this->settings['flexform']['showCategory'] ? $catId = $this->settings['flexform']['showCategory']:$catId = $this->settings['listView']['showCategory'];
// print $catId;
if (!$catId || $this->settings['flexform']['showCategory'] == '-1') {
$designs = $this->designRepository->findAll();
} else {
// $designs = $this->designRepository->findByCategory($catId);
$designs = $this->designRepository->findByCategoryGrouped($catId); // THIS
$categories = $this->categoryRepository->getCategories($catId); // THIS
}
// indhold forsvinder hvis næste linje slettes
$this->view->assign('designs', $designs, "L", $GLOBALS['TSFE']->sys_language_uid);
$this->view->assign('catId', $catId);
$this->view->assign('categories', $categories);
}
You can inject every repository of every installed extbase extension. Just add the dependency injection code to your controller. Depending on your TYPO3 version ist either:
TYPO3 >= 6.0:
Note that the
@inject
Annotation does not perform very well in comparison to a dedicated inject method. So if you need to tweek the performance of your application and have many injections in yout controller you should consider switching to inject methods:TYPO3 = 4.7:
TYPO3 < 4.7
In any case you can use
$this->someRepository
with all its methods in the controller you injected the repository into.Edit: fixed typo.
Edit: After adding a Dependency Injection, you have to clear the cache!