[TYPO3-mvc] ExtJS, AJAX in Extbase

Michael Knoll mimi at kaktusteam.de
Mon Jan 24 15:03:50 CET 2011


Am 24.01.11 14:37, schrieb Dawid Pacholczyk:
> W dniu 2011-01-24 14:32, Michael Knoll pisze:
>> Hi Dawid,
>>
>> don't know, whether this helps you out... but as far as I know, there is
>> now dedicated AJAX handling in ExtBase. So what I did looks something
>> like that:
>>
>> class Tx_Yag_Controller_AjaxController extends
>> Tx_Extbase_MVC_Controller_ActionController {
>>
>> /* ... */
>>
>> /**
>> * Deletes an item
>> *
>> * @param int $itemUid UID of item
>> */
>> public function deleteItemAction($itemUid) {
>> $item = $this->itemRepository->findByUid(intval($itemUid)); /*@var $item
>> Tx_Yag_Domain_Model_Item */
>> $item->delete();
>>
>> // As we cancel ExtBase lifecycle in this action, we have to persist
>> manually!
>> $this->persistenceManager->persistAll();
>>
>> // Do some ajax output
>> ob_clean();
>> echo "OK";
>> exit();
>> }
>>
>>
>>
>> /**
>> * Updates name of a given item
>> *
>> * @param int $itemUid UID of item to update
>> * @param string $itemTitle New name of item
>> */
>> public function updateItemNameAction($itemUid, $itemTitle) {
>> $item = $this->itemRepository->findByUid(intval($itemUid)); /*@var $item
>> Tx_Yag_Domain_Model_Item */
>> $item->setTitle($itemTitle);
>>
>> $this->itemRepository->update($item);
>> $this->persistenceManager->persistAll();
>>
>> ob_clean();
>> echo "OK";
>> exit();
>> }
>>
>>
>> }
>>
>>
>> If there is a better way on doing this, it would be great to get a
>> solution :-)
>>
>> Greetings
>>
>> Mimi
>>
>>
>>
>>
>> Am 24.01.11 14:26, schrieb Dawid Pacholczyk:
>>> <f:be.container /> <--- now that is magick. I`ve lost 2 days to find a
>>> way to include extjs :) thank you very much. Where I can find some
>>> documentation to that ?
>>>
>>> Now the second thing. I should now write functions in ExtJS ? How to
>>> handle Ajax and do some operation ? Can I add a record to database or
>>> something ?
>>>
>>> Best regards,
>>> Dawid Pacholczyk
>>>
>>> W dniu 2011-01-24 14:15, Stefan Isak pisze:
>>>> Hi,
>>>>
>>>> you can create a backend layout in
>>>> EXT:Resources/Private/Backend/Layouts/myLayout.html
>>>>
>>>> Here is an example of myLayout.html:
>>>>
>>>> 8< 8< 8< 8< 8< 8< 8< 8< 8<
>>>> <f:be.container pageTitle="MyTitle" loadExtJs="TRUE"
>>>> loadExtJsTheme="TRUE">
>>>>
>>>> <link href="{f:uri.resource(path:'Backend/Styles/MyStyles.css')}"
>>>> rel="stylesheet" />
>>>> <div class="typo3-fullDoc">
>>>> <div id="typo3-docheader">
>>>> <div id="typo3-docheader-row1">
>>>> <div class="buttonsleft">
>>>> <f:render section="iconButtons" />
>>>> </div>
>>>> <div class="buttonsright">
>>>> <f:be.buttons.shortcut />
>>>> </div>
>>>> </div>
>>>> <div id="typo3-docheader-row2">
>>>> <div class="docheader-row2-left">
>>>> <f:be.buttons.csh />
>>>> <f:be.menus.actionMenu>
>>>> <f:be.menus.actionMenuItem label="Overview" controller="MyController"
>>>> action="index" />
>>>> </f:be.menus.actionMenu>
>>>> </div>
>>>>
>>>> <div class="docheader-row2-right">
>>>> <f:be.pagePath />
>>>> <f:be.pageInfo />
>>>> </div>
>>>> </div>
>>>> </div>
>>>> <div id="typo3-docbody">
>>>> <div id="typo3-inner-docbody">
>>>> <f:renderFlashMessages class="tx-extbase-flash-message" />
>>>>
>>>> <f:render section="content" />
>>>>
>>>> <script src="{f:uri.resource(path:'Backend/JavaScript/MyScript.js')}"
>>>> type="text/javascript"></script>
>>>> </div>
>>>> </div>
>>>> </div>
>>>> </f:be.container>
>>>> 8< 8< 8< 8< 8< 8< 8< 8< 8<
>>>>
>>>> Especially have a look at<f:be.container />. Using 4.4.x you may need
>>>> to add loadExtJs="TRUE" and loadExtJsTheme="TRUE". AFAIK in TYPO3
>>>> 4.5.x it's included per default.
>>>>
>>>> Within your JS file you can use urls with the following scheme to make
>>>> ajax calls:
>>>> mod.php?M=web_MyextTxMyextM1&tx_myext_web_myexttxmyextm1[controller]=MyController&tx_myext_web_myexttxmyextm1[action]=index
>>>>
>>>>
>>>>
>>>>
>>>> 'M1' in this url is according to your configuration in ext_tables.php>
>>>> Tx_Extbase_Utility_Extension::registerModule( ... )
>>>>
>>>> Hope those things make it way easier for you.
>>>>
>>>> So long
>>>> Stefan
>>>>
>>>> On 24.01.2011, at 13:46, Dawid Pacholczyk wrote:
>>>>
>>>>> Hi List !!
>>>>> I just can`t do it. How can I run extjs and ajax in my extbase BE
>>>>> module ? I`m looking at workspace and othere exts and nothing.
>>>>>
>>>>> For example what is pageRenderer ? I can`t find any declaration of
>>>>> this object and I still get some errors. Please gimme some good link
>>>>> where I can read about that.
>>>>>
>>>>> best regards,
>>>>> Dawid Pacholczyk
>>>>> _______________________________________________
>>>>> TYPO3-project-typo3v4mvc mailing list
>>>>> TYPO3-project-typo3v4mvc at lists.typo3.org
>>>>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>>>>>
>>>>>
>>>>
>>>
>>
>
> I don`t get it. You just show me a standard code.
>
> What is this ?
>
>  > ob_clean();
>  > echo "OK";
>  > exit();
>
> How should I build link to make an ajax action ? Should I worry for
> httpRequest ? I just don`t get your example :( But thank you for reply !

That's my way of returning AJAX response... if you don't clean 
output-stream, you will get a Typo3 page instead... which is not what 
you want, when calling an ajax action :-)

Yes - you do a normal http request for that.

Seems like, there is a newer method to handle that in current version... 
so never mind :-)

Greez

Mimi




More information about the TYPO3-project-typo3v4mvc mailing list