问题描述
我有几个像这样的控制器:CategoryController和NewsController以及用于类别,新闻和资源库的领域模型.
I have several Controllers like those: CategoryController and NewsControllerAs well as the domain models for category and news and reposirtories for both.
在NewsController中,我像这样进行dependencyInjection(与categoryController中的方法相同):
In the NewsController I do a dependencyInjection like this (the same way as in categoryController):
/**
* categoryRepository
*
* @var Tx_MyExtension_Domain_Repository_CategoryRepository
*/
protected $categoryRepository;
/**
* injectCategoryRepository
*
* @param Tx_MyExtension_Domain_Repository_CategoryRepository $CategoryRepository
* @return void
*/
public function injectCategoryRepository(Tx_MyExtension_Domain_Repository_CategoryRepository $categoryRepository) {
$this->categoryRepository = $categoryRepository;
}
当我现在尝试使用类似这样的功能时:
When I'm trying now in a function something like this:
/**
* action getCategoriesAjax
*
* @param Tx_MyExtension_Domain_Model_News
* @return void
*/
public function getCategoriesAjaxAction() {
$categories = $this->categoryRepository->findAll();
$this->view->assign('categories',$categories);
}
我得到一个空结果.
对我来说,奇怪的是,如果我在CategoryController中执行此操作,则相同的功能将像charm一样工作并返回数据库中的所有元素,对我来说甚至更陌生的是,如果我执行$ this-> categoryRepository-> findByUid(1)我得到了正确的元素作为结果.
The strange thing for me is, that if I'm doing this in the CategoryController, the same function works like charm and returns all elements in the database and even stranger for me is, that if I do a $this->categoryRepository->findByUid(1) I get the correct element as result.
我还在我的categoryRepository中添加了一个测试功能:
I also added to my categoryRepository a test function:
public function test(){
$query = $this->createQuery();
$result = $query->execute();
$amount = $result.count();
}
如果我从categoryController调用此函数,则会取回正确数量的元素.如果我是从newsController调用的,则返回"0" ...
If I call this function from categoryController, I get back the correct amount of elements. If I'm calling this from my newsController I get "0" back...
我不明白...
我想念什么???我的错误在哪里?
What do I miss???Where is my mistake?
推荐答案
这困扰了我好几天(或几周).如果您没有在TypoScript中的某处定义以下内容,则StoragePid(对数据库项所连接到的页面的引用)不会使其进入数据库查询:
This has bugged me for days (or weeks). The StoragePid (the reference to the page where your database items are attached to) does not make it to the database query if you don't define the following somewhere in your TypoScript:
plugin.tx_myextension.persistence.storagePid = 4
将其放在您的Page-TS中,并且Tx_Extbase_Persistence_Repository中的findAll方法应该可以正常工作.
Put this in your Page-TS and the findAll method from Tx_Extbase_Persistence_Repository should be working fine.
周.
这篇关于extbase存储库findAll()返回结果为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!