[TYPO3-mvc] Generating a link to a backend-module / action

Bastian Waidelich bastian.waidelich at typo3.org
Mon Nov 29 11:31:55 CET 2010


Tolleiv.Nietsch wrote:

Hi Tolleiv,

> the code for generating a link to our module is one thing in the
> workspace-extension which I'm not proud of [...]

> $ctrl =
> t3lib_div::makeInstance('Tx_Workspaces_Controller_PreviewController');
> $uriBuilder =
> t3lib_div::makeInstance('Tx_Extbase_MVC_Web_Routing_UriBuilder');
> $additionalParams =
> '&tx_workspaces_web_workspacesworkspaces%5Bcontroller%5D=Preview&M=web_WorkspacesWorkspaces&id=';
> $viewScript = '/' . $GLOBALS['BACK_PATH'] . $uriBuilder->uriFor('index',
> array(), $ctrl, 'workspaces', 'web_workspacesworkspaces') .
> $additionalParams;

Why do you instantiate the controller?
The 3rd parameter of Tx_Extbase_MVC_Web_Routing_UriBuilder::uriFor() is 
expected to be the controller name as simple string, not the object. I'm 
surprised, that it works like this at all ;)

$uriBuilder = 
t3lib_div::makeInstance('Tx_Extbase_MVC_Web_Routing_UriBuilder');
$uriBuilder->setArguments(array('M' => 'web_WorkspacesWorkspaces'));
$viewScript = '/' . $backPath . $uriBuilder->uriFor('index', array(), 
'Preview', 'workspaces', 'web_workspacesworkspaces');

But you should instantiate Extbase/Fluid classes with the ObjectManager 
rather than with t3lib_div::makeInstance() in order to make use of 
Dependency Injection (Otherwise you'll might be missing some objects to 
be set in the UriBuilder).
Unfortunately there's still a bug in the object container [1], so you'll 
have to instantiate the ConfigurationManager too:

$objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
// FIXME this is needed atm in order to correctly instantiate the 
ConfigurationManager
$objectManager->get('Tx_Extbase_Configuration_ConfigurationManagerInterface');
$uriBuilder = $objectManager->get('Tx_Extbase_MVC_Web_Routing_UriBuilder');
// This should not be needed as well:
$uriBuilder->setArguments(array('M' => 'web_WorkspacesWorkspaces'));

I'll try to fix this issue in the DI container this afternoon together 
with Sebastian.

Buut.. The UriBuilder also relies on the MVC request currently which 
won't be available when your not inside an Extbase extension..
Maybe we need some factory here..

[1] http://forge.typo3.org/issues/11015


More information about the TYPO3-project-typo3v4mvc mailing list