kap*_*ale 9 null repository findall extbase
我有几个像这样的控制器:CategoryController和NewsController以及类别和新闻的域模型以及两者的reposirtories.
在NewsController中,我像这样执行dependencyInjection(与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;
}
Run Code Online (Sandbox Code Playgroud)
当我现在尝试这样的函数时:
/**
* action getCategoriesAjax
*
* @param Tx_MyExtension_Domain_Model_News
* @return void
*/
public function getCategoriesAjaxAction() {
$categories = $this->categoryRepository->findAll();
$this->view->assign('categories',$categories);
}
Run Code Online (Sandbox Code Playgroud)
我得到一个空的结果.
对我来说奇怪的是,如果我在CategoryController中这样做,同样的函数就像魅力一样工作并返回数据库中的所有元素,对我来说更奇怪的是,如果我做一个$ this-> categoryRepository-> findByUid(1)我得到了正确的元素作为结果.
我还在我的categoryRepository中添加了一个测试函数:
public function test(){
$query = $this->createQuery();
$result = $query->execute();
$amount = $result.count();
}
Run Code Online (Sandbox Code Playgroud)
如果我从categoryController调用此函数,我会返回正确数量的元素.如果我从我的newsController调用它,我得到"0"回...
我不明白......
我有什么想念??? 我的错误在哪里?
Hen*_*rik 12
这已经困扰了我好几天(或几周).如果您未在TypoScript中的某处定义以下内容,则StoragePid(对数据库项目所附加的页面的引用)不会进入数据库查询:
plugin.tx_myextension.persistence.storagePid = 4
Run Code Online (Sandbox Code Playgroud)
把它放在你的Page-TS中,来自Tx_Extbase_Persistence_Repository的findAll方法应该可以正常工作.
周.
你确定findAll()的返回值为NULL吗?
可能是您的依赖注入不起作用。那么异常应该是这样的:
findAll() 在非对象上调用($this->categoryRepository)
同样在您的injectCategoryRepository中,您$categoryRepository
以lowerCamelCase编写,并在UpperCamelCase注释中编写 $CategoryRepository
希望这可以帮助..
归档时间: |
|
查看次数: |
10046 次 |
最近记录: |