菜单

Extbase – how to call controller action via Typoscript directly

2015年11月9日 - typoscript

If you have an extbase extension and you need to call a controller action via TypoScript, things have changed from TYPO3 4.7 to 6.1. TYPO3 6 has a lot of code rewritten, depends heavily on PHP namespaces and extbase extensions from earlier versions will no longer work.
To get started with all the necessary bootstrap code for a new extension, use the extension “extension_builder” from TER.

Let’s assume we have a little extension and we want to assign the result of a direct call of a controller action to a TS object.
Our controller code looks like this:

namespace MyVendorName\MyExtName\Controller;
class MyModelController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {

public function myTestAction() {
return “some string”;
}

Please notice the namespace, this is very important! Your ext_localconf.php should look something like this:


\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
‘MyVendorName.’ . $_EXTKEY,
‘Pi1’,
array(
‘MyModel’ => ‘myTest’,
),
// non-cacheable actions
array(

)
);

‘Pi1’ is simply the name of the frontend plugin

TypoScript config

Now we set up a TS-object which should hold the output of our “myTestAction” method.

lib.myObj = USER
lib.myObj = 10
10 {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
pluginName = Pi1
extensionName = MyExtName
controller = MyModel
vendorName = MyVendorName
action = myTest
switchableControllerActions {
MyModel {
1 = myTest
}
}

settings =< plugin.tx_myextname.settings persistence =< plugin.tx_myextname.persistence view =< plugin.tx_myextname.view update =< plugin.tx_myextname.update } The parameter “vendorName” is new and very important – it won’t work without it. Take care of the camel case notation too – the whole extbase framework is based on this case-sensitive coding convention. Now we are done – our controller action is directly called via TypoScript.

发表评论

电子邮件地址不会被公开。 必填项已用*标注