Discussion:
[TYPO3-english] Extbase handler for Ajax calls in BE and FE
Jan Kornblum
2013-11-22 11:25:45 UTC
Permalink
Hello newsgroup,

are there any possibilities given in the current (6.1) core to call
Extbase actions in an Ajax context from BE (using /typo3/ajax.php) and
from FE (using the eID mechanism)?

And, if not yet exists, wouldn't it be a good feature request to
integrate something like this into the (6.2) core?

The only thing i've found regarding this are several custom approaches
each using own Extbase dispatchers...

Kind regards, Jan
Benjamin Mack
2013-11-22 12:27:46 UTC
Permalink
Hey Jan,

if you use extbase in FE, you most probably need all the magic (and that
is TypoScript loaded for a specific page). I therefore recommend to use
a separate page type to do this.

For BE i have no experience how to instantiate Extbase in AjaxID.

All the best,
Benni.
Xavier Perseguers
2013-11-22 13:09:22 UTC
Permalink
Hi,
Post by Benjamin Mack
if you use extbase in FE, you most probably need all the magic (and that
is TypoScript loaded for a specific page). I therefore recommend to use
a separate page type to do this.
For BE i have no experience how to instantiate Extbase in AjaxID.
I would simply create a dedicated AJAX action in your controller that
returns what you need.

Kind regards
--
Xavier Perseguers
Release Manager TYPO3 4.6

TYPO3 .... inspiring people to share!
Get involved: http://typo3.org
Jan Kornblum
2013-11-22 14:00:03 UTC
Permalink
Hi Benjamin and Xavier,

thanks for your replies.
Post by Xavier Perseguers
Post by Benjamin Mack
if you use extbase in FE, you most probably need all the magic (and that
is TypoScript loaded for a specific page). I therefore recommend to use
a separate page type to do this.
For BE i have no experience how to instantiate Extbase in AjaxID.
I would simply create a dedicated AJAX action in your controller that
returns what you need.
In FE i tried both pageType and eID [1]. In case of pageType there is
no problem to call an Ajax action. In case of eID it seems to be
neccessary to write an own ajax-extbase dispatcher, isn't it?

But in BE, how can i call an Extbase action here when using AjaxID /
ajax.php? There is a good documentation about using Ajax in BE in
general [2], but it contains no hints regarding Extbase.

I've also read about ExtDirect [3], but i have no idea at all if this
should be used in this context?

Kind regards, Jan

[1] http://typo3.org/documentation/snippets/sd/455/

[2]
http://typo3.org/documentation/document-library/core-documentation/doc_core_api/4.2.0/view/3/9/

[3] http://wiki.typo3.org/ExtDirect
François Suter
2013-11-25 06:46:01 UTC
Permalink
Hi Jan,
Post by Jan Kornblum
But in BE, how can i call an Extbase action here when using AjaxID /
ajax.php? There is a good documentation about using Ajax in BE in
general [2], but it contains no hints regarding Extbase.
Beware old links:
http://docs.typo3.org/typo3cms/CoreApiReference/JavaScript/Ajax/Index.html

;-)
Post by Jan Kornblum
I've also read about ExtDirect [3], but i have no idea at all if this
should be used in this context?
ExtDirect is better documented here:

http://docs.typo3.org/typo3cms/CoreApiReference/JavaScript/UsingExtjs/ExtDirect/Index.html

The advantage of ExtDirect is that you can directly map JS methods to
PHP methods. But ExtJS is rather a pain to work with.

Also ExtDirect is supposed to work in the FE, but I never managed to
make it work, and the knowledge seems lost to the community.

Cheers
--
Francois Suter

Work: Cobweb Development Sarl - http://www.cobweb.ch

TYPO3: Help the project! - http://typo3.org/contribute/

Appreciate my work? Support me -
http://www.monpetitcoin.com/en/francois/support-me/
Jan Kornblum
2013-11-25 10:01:11 UTC
Permalink
Hi Fran?ois,
Post by François Suter
Post by Jan Kornblum
But in BE, how can i call an Extbase action here when using AjaxID /
ajax.php? There is a good documentation about using Ajax in BE in
general [2], but it contains no hints regarding Extbase.
http://docs.typo3.org/typo3cms/CoreApiReference/JavaScript/Ajax/Index.html
;-)
Post by Jan Kornblum
I've also read about ExtDirect [3], but i have no idea at all if this
should be used in this context?
http://docs.typo3.org/typo3cms/CoreApiReference/JavaScript/UsingExtjs/ExtDirect/Index.html
The advantage of ExtDirect is that you can directly map JS methods to PHP
methods. But ExtJS is rather a pain to work with.
Also ExtDirect is supposed to work in the FE, but I never managed to make it
work, and the knowledge seems lost to the community.
Thanks for the updated links and your explanations regarding ExtDirect.

But still no news regarding extbase in BE :( If anybody has already
used extbase together with ajax in BE, please let me know ;)

Kind regards, Jan
Xavier Perseguers
2013-11-25 10:13:11 UTC
Permalink
Hi Jan,
But still no news regarding extbase in BE :( If anybody has already used
extbase together with ajax in BE, please let me know ;)
The Extension Manager is doing that. Example links are generated as
standard "<a href" links in the template, then are processed by jquery
(main.js):

$('.t3-icon-system-extension-update').parent().each(function() {
$(this).data('href', $(this).attr('href'));
$(this).attr('href', '#');
$(this).addClass('transformed');
$(this).click(function() {
$('.typo3-extension-manager').mask();
$.ajax({
url: $(this).data('href'),
dataType: 'json',
success: updateExtension
});
});
});

dataType: 'json' will ask extbase to use JSON as return type and thus
instruct it to search for a .json template instead of .html.

remove extension is done slightly differently (link comes from the
confirmation dialog) but idea is the same:

if (button == 'yes') {
$('.typo3-extension-manager').mask();
$.ajax({
url: dialog.url,
dataType: 'json',
success: removeExtension
});
}

The controller action does nothing special:

/**
* Remove an extension (if it is still installed, uninstall it first)
*
* @param string $extension
*/
protected function removeExtensionAction($extension) {
$success = TRUE;
$message = '';
try {
if
(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extension)) {
$this->installUtility->uninstall($extension);
}
$this->installUtility->removeExtension($extension);
} catch
(\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
$message = $e->getMessage();
$success = FALSE;
}
$this->view->assign('success', $success)->assign('message',
$message)->assign('extension', $extension);
}

and the corresponding view (RemoveExtension.json) is straightforward:

{namespace em=TYPO3\CMS\Extensionmanager\ViewHelpers}
<em:format.jsonEncode additionalAttributes="{success:success,
message:message, extension:extension}" />

So this is a full example on AJAX call to Extbase in Backend, not using
ExtJS (which is not so beloved anymore) but jQuery.

HTH
--
Xavier Perseguers
Release Manager TYPO3 4.6

TYPO3 .... inspiring people to share!
Get involved: http://typo3.org
Jan Kornblum
2013-11-25 10:52:08 UTC
Permalink
Hi Xavier,
Post by Xavier Perseguers
The Extension Manager is doing that. Example links are generated as
standard "<a href" links in the template, then are processed by jquery
...
Post by Xavier Perseguers
So this is a full example on AJAX call to Extbase in Backend, not using
ExtJS (which is not so beloved anymore) but jQuery.
Great, thanks for your explanations. The only thing i do not understand
is the following:

The EM example links all call "typo3/mod.php" with params to the module
and controller and action. This is clear to me. But there is no use of
AjaxID (typo3/ajax.php), as explained in Francois link and used by me
in this way until now.

is there a best practise? Or, what just came into my mind: It seems to
me that AjaxID for BE is something similar like eID for FE. And using
Ajax calls to "typo3/mod.php" in BE could be compared to using Ajax
calls to an own pageType in FE. Could this be right?

Kind regards, Jan
Xavier Perseguers
2013-11-25 13:19:50 UTC
Permalink
Hi Jan,
Post by Jan Kornblum
The EM example links all call "typo3/mod.php" with params to the module
and controller and action. This is clear to me. But there is no use of
AjaxID (typo3/ajax.php), as explained in Francois link and used by me in
this way until now.
True.
Post by Jan Kornblum
is there a best practise? Or, what just came into my mind: It seems to
me that AjaxID for BE is something similar like eID for FE. And using
Ajax calls to "typo3/mod.php" in BE could be compared to using Ajax
calls to an own pageType in FE. Could this be right?
Just as with eID where you have to instantiate the whole resources
yourself, as it is thought to be lightweight, you're right, dispatching
through mod.php is exactly the same as dispatching in FE using a custom
pageType.

Dispatching through AjaxID is thus comparable to dispatching through
eID, it forces you to instantiate the whole framework. As seen numerous
times on mailing lists, using a custom pageType is "easier" when it
comes to Extbase-based extensions.

I did not create much AJAX stuff in BE so I cannot tell you which way is
the best way but IMHO AjaxID is old and not the best options anymore
with Extbase. I would be pragmatic and take what has been done recently
in Core modules as "official way" and as such dispatching your AJAX
calls through mod.php is IMHO the way to go.

Kind regards
--
Xavier Perseguers
Release Manager TYPO3 4.6

TYPO3 .... inspiring people to share!
Get involved: http://typo3.org
Jan Kornblum
2013-11-25 13:23:42 UTC
Permalink
Hi Xavier,

great! Thank you very much for the time you've spent on this...

Kind regards, Jan

Loading...