Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extbase repository findAll() returns result null

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?

like image 205
kapale Avatar asked Jul 22 '12 17:07

kapale


2 Answers

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.

like image 123
Hendrik Avatar answered Sep 18 '22 13:09

Hendrik


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.

like image 29
greg Avatar answered Sep 16 '22 13:09

greg