[TYPO3-dev] Tx_Extbase_Persistence_Repository behaves differently in different actions

Braulio J. Solano-Rojas braulio at solsoft.biz
Fri Mar 19 03:30:53 CET 2010


Hello.

I am sorry if this is the wrong list to ask.

Basically, I've been experimenting with the extbase_kickstarter (in fact 
I've sent a pair of patches) and with extbase itself.

I am trying to build a very simple extension to handle a magazine.

I have this two actions in my ArticleController.php:

/**
  * index action
  *
  * @return string The rendered index action
  */
public function indexAction() {
	$lastEdition = $this->editionRepository->findLast();
	$this->view->assign('lastEditionArticles', $lastEdition->getArticles());
}
	
/**
  * randomArticles action
  *
  * @return string The rendered randomArticles action
  */
public function randomArticlesAction() {
	$lastEdition = $this->editionRepository->findLast();
	$lastEditionArticles = $lastEdition->getArticles();
	$randomArticles = array();
	// some code to produce random articles...
	$this->view->assign('randomArticles', $randomArticles);
}

With this initializer:

/**
  * Initializes the current action
  *
  * @return void
  */
public function initializeAction() {
	$this->articleRepository = 
t3lib_div::makeInstance('Tx_Magazine_Domain_Repository_ArticleRepository');
	$this->editionRepository = 
t3lib_div::makeInstance('Tx_Magazine_Domain_Repository_EditionRepository');
}

What is very strange is that in the index action I get the last edition 
but in the randomArticles action I don't (it returns NULL).  I.E., 
$this->editionRepository->findLast() does not work equally on both 
methods.  However, both are running the same code from my Edition 
Repository:

/**
  * Finds the last edition
  *
  * @return Tx_Magazine_Domain_Model_Edition
  */
public function findLast() {
	$query = $this->createQuery();
	$editions = $query->matching($query->equals('last_edition', 1))
		->setOrderings(array('crdate' => 
Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING))
		->setLimit(1)
		->execute();
	return (count($editions) == 0) ? NULL : current($editions);
}

This has been puzzling me all day...

I've been searching in the docs existing so far and looked very closely 
a the blog example extension, but it is not enough to understand what's 
happening.

Do you have a clue?

Best regards,

B.




More information about the TYPO3-dev mailing list