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.
Die Artikel war sehr hilfreich. Ich habe aber noch eine Frage: wie würde die Ausgabe des Typoscript Variables in Fluid aussehen?
{lib.myObj}
oder
Was ist die Unterschied?
Was tun wenn der Beispiel nicht funktioniert?
Hallo Jennifer,
Dieser Code lädt ja den Controller inkl. den entsprechenden Views und kann bspw. in einem PAGE Objekt direkt verwendet werden. Ich verwende das bspw., wenn ich Widgtets auf Seiten integriere,
z.b.
page = PAGE
page.10.variables.myWidget < lib.myObj