4
是否可以在不同的控制器中调用一个函数?我需要调用在designRepository.php FindByCategoryGrouped($catId)
和getCategories($catId)
从categoryRepository.phpTYPO3 - 调用另一个存储库
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);
}
我的listAction在上面的代码中,来自designController.php。在该文件中,我要补充 /** * (AT),无功\供应商\延期\域\库\ SomeRepository *(AT)注入 */ 保护$ someRepository; 或者我应该创建categoryController.php并将其添加到那里? –
您不必创建新的控制器。只需将categoryRepository注入到您的DesignController中,就像您(有希望)使用designRepository一样 – Daniel
“类DesignController延伸\ TYPO3 \ CMS \ Extbase \的mvc \控制器\ {的ActionController \t/** \t * designRepository \t * \t *(在)VAR \ TYPO3 \ OrigKentaurProducts \域\库\ DesignRepository \t *(at)inject \t */ \t protected $ designRepository; \t \t/** \t *(AT),无功\ TYPO3 \ OrigKentaurProducts \域\库\ CategoryRepository \t *(AT)注入 \t */ \t保护$ categoryRepository;” And:'$ categories = $ this-> categoryRepository-> getCategories($ catId);' 这给了我 在CategoryRepository.php我有“非对象上调用一个成员函数getCategories()”: “公共职能getCategories($ CATID){” –