TYPO3-调用另一个存储库 [英] TYPO3 - Call another repository
问题描述
是否可以在不同的控制器中调用函数?我需要在designRepository.php中调用FindByCategoryGrouped($catId)
,从categoryRepository.php中调用getCategories($catId)
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);
}
推荐答案
您可以注入每个已安装的extbase扩展的每个存储库.只需将依赖项注入代码添加到您的控制器即可.取决于您的TYPO3版本,或者:
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:
/**
* @var \Vendor\Extension\Domain\Repository\SomeRepository
* @inject
*/
protected $someRepository;
请注意,与专用的注入方法相比,@inject
注释的执行效果不是很好.因此,如果您需要调整应用程序的性能,并在控制器中进行多次注入,则应考虑切换到注入方法:
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:
/**
* @var \Vendor\Extension\Domain\Repository\SomeRepository
*/
protected $someRepository;
/**
* @param \Vendor\Extension\Domain\Repository\SomeRepository
*/
public function injectSomeRepository(\Vendor\Extension\Domain\Repository\SomeRepository $someRepository) {
$this->someRepository = $someRepository;
}
TYPO3 = 4.7:
/**
* @var Tx_MyExtension_Domain_Repository_SomeRepository
* @inject
*/
protected $someRepository;
TYPO3< 4.7
/**
* @var Tx_MyExtension_Domain_Repository_SomeRepository
*/
protected $someRepository;
/**
* Inject SomeRepository
* @param Tx_MyExtension_Domain_Repository_SomeRepository $someRepository
* @return void
*/
public function injectSomeRepository(Tx_MyExtension_Domain_Repository_SomeRepository $someRepository) {
$this->someRepository = $someRepository;
}
无论如何,您都可以在将存储库注入到的控制器中使用$this->someRepository
及其所有方法.
In any case you can use $this->someRepository
with all its methods in the controller you injected the repository into.
固定错字.
添加依赖项注入后,您必须清除缓存!
这篇关于TYPO3-调用另一个存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!