extbase repository findAll() returns result null
Asked Answered
S

4

9

I have several Controllers like those: CategoryController and NewsController As well as the domain models for category and news and reposirtories for both.

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);
}

I get an empty result back.

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.

I also added to my categoryRepository a test function:

public function test(){
  $query = $this->createQuery();
  $result = $query->execute();
  $amount = $result.count();
}

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...

I don't get it...

What do I miss??? Where is my mistake?

Somewhere answered 22/7, 2012 at 17:11 Comment(0)
H
12

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

Put this in your Page-TS and the findAll method from Tx_Extbase_Persistence_Repository should be working fine.

Weeks.

Hedveh answered 18/10, 2012 at 12:1 Comment(0)
K
3

Or you could force Repository to ignore Storage Page:

class MymodelRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
  public function initializeObject() {

  $this->defaultQuerySettings = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
  $this->defaultQuerySettings->setRespectStoragePage(FALSE);
 }
}

From now on your Repository will pull every record from the database.

Kimberelykimberlee answered 1/9, 2014 at 10:8 Comment(1)
see documentation for all options: wiki.typo3.org/…Verdieverdigris
B
2

Are you sure that the return value of findAll() is NULL?

It could be that your Dependency Injection doesn't work. Then the Exception should be something like this:

findAll() is called on a Non-Object ($this->categoryRepository)

Also in your injectCategoryRepository you write $categoryRepository in lowerCamelCase and in the annotations in UpperCamelCase $CategoryRepository

Hope this helps..

Battleax answered 23/7, 2012 at 9:55 Comment(2)
Thx for the hint with the upper/lowerCamelCase. I hopped that this would be the solution... I'll have a deeper look on this to be sure not to have this on severeal places. I don't get an error, I get a Tx_Extbase_Persistence_QueryResult object back, but without a result. Neither do I get an error message. Thank you for your support!Somewhere
Found the UpperCamelCase problem on a second possition, but unfortunately it didn't solved my problem. (After deleting all caches)Somewhere
M
1

As Hendrik said you can set it in your page-TS. Another solution is: in you BE, edit your page content that contains the plugin, select the Sys Folder, in which your db items are stored. This is found under the tab "Behaviour" for Typo3 v6.1

Melessa answered 31/1, 2014 at 11:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.