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

Xavier Perseguers typo3 at perseguers.ch
Mon Aug 3 11:43:19 CEST 2009


Hi Robert,

>> 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>
> 
> 
> Hmm, looks a bit dirty having a genres.html file producing JSON.

I know ;-)

> In FLOW3 I'm using the concept of formats: the request object contains 
> the currently
> requested format (html, json, xml, ...) and the action controller will 
> automatically
> select the right Fluid template or view. The big advantage is that you 
> don't need to modify
> the controller at all for providing a JSON view.

As you said it's for FLOW3. I'm not sure it exists for Extbase.

> Some untested sample code (note the small name changes):
> 
> class Tx_MvcExtjsSamples_Controller_GenreController {
> 
>    public function indexAction() {
>       $genreRepository = 
> t3lib_div::makeInstance('Tx_MvcExtjsSamples_Domain_Repository_GenreRepository'); 
> 
>       $genres = $genreRepository->findAll();
>       $this->view->assign('genres', $genres);
>    }
> 
> }
> 
> index.html:
>    <ul>
>    <f:for each="{genres}" as "genre">
>       <li>{genre.title}</li>
>    </f:for>
>    <ul>
> 
> index.json:
> {namespace mvcextjs=Tx_MvcExtjsSamples_ViewHelpers}
> <mvcextjs:json>{genres}</mvcextjs:json>

Yes the difference is only in the file extension, which would be much 
better but needs support from Extbase.

Cheers

-- 
Xavier Perseguers
MVC ExtJS Samples Leader

http://forge.typo3.org/projects/show/extension-mvc_extjs_samples


More information about the TYPO3-project-typo3v4mvc mailing list