[TYPO3-mvc] [INFO] How-to do AJAX with Extbase

Xavier Perseguers typo3 at perseguers.ch
Sat Aug 1 10:41:37 CEST 2009


Hi,

I just enhanced the JSON encoding part. Instead of:

> public function genresAction() {
>     $genreRepository = 
> t3lib_div::makeInstance('Tx_MvcExtjsSamples_Domain_Model_GenreRepository');
>     /* @var $genreRepository 
> Tx_MvcExtjsSamples_Domain_Model_GenreRepository */
> 
>         // Retrieve all genres from repository
>     $genres = $genreRepository->findAll();
> 
>         // Convert Tx_MvcExtjsSamples_Domain_Model_Genre objects to an 
> array
>     $arr = Tx_MvcExtjsSamples_ExtJS_Utility::encodeArrayForJSON($genres);
> 
>         // Send the JSON response
>     return Tx_MvcExtjsSamples_ExtJS_Utility::getJSON($arr);
> }

We now have

public function genresAction() {
	$genreRepository = 
t3lib_div::makeInstance('Tx_MvcExtjsSamples_Domain_Model_GenreRepository');
	/* @var $genreRepository Tx_MvcExtjsSamples_Domain_Model_GenreRepository */

		// Retrieve all genres from repository
	$genres = $genreRepository->findAll();

	$this->view->assign('genres', $genres);
}

with genres.html:

{namespace mvcextjs=Tx_MvcExtjsSamples_ViewHelpers}
<mvcextjs:json>{genres}</mvcextjs:json>

Let's take advantage of Fluid... ;-)

-- 
Xavier Perseguers
http://xavier.perseguers.ch/en

One contribution a day keeps the fork away


More information about the TYPO3-project-typo3v4mvc mailing list