[TYPO3-mvc] using views from a controller in another controller - possible or not?

Dennis Ahrens dennis.ahrens at googlemail.com
Wed Sep 22 18:23:04 CEST 2010


Hi again,

i've tested the approach and the result is the following code:

class Tx_FhhForschungsprojekte_Controller_PersonController extends 
Tx_FhhPersonen_Controller_PersonController {
	
	/**
	 * Initializes the view before invoking an action method.
	 *
	 * We change the template paths here to point to fhh_personen extension.
	 *
	 * @param Tx_Extbase_View_ViewInterface $view The view to be initialized
	 * @return void
	 * @api
	 */
	protected function initializeView(Tx_Extbase_MVC_View_ViewInterface 
&$view) {
		$templatePath = 
t3lib_div::getFileAbsFileName('EXT:fhh_personen/Resources/Private/Backend/Templates/');
		$layoutPath = 
t3lib_div::getFileAbsFileName('EXT:fhh_personen/Resources/Private/Backend/Layouts/');
		$partialPath = 
t3lib_div::getFileAbsFileName('EXT:fhh_personen/Resources/Private/Backend/Partials/');
		
		$view = $this->objectManager->getObject('Tx_Fluid_View_TemplateView');
		$controllerContext = $this->buildControllerContext();
		$view->setControllerContext($controllerContext);
		
		$view->setTemplateRootPath($templatePath);
		$view->setLayoutRootPath($layoutPath);
		$view->setPartialRootPath($partialPath);
		
		if (method_exists($view, 'injectSettings')) {
			$view->injectSettings($this->settings);
		}
		$view->initializeView(); // In FLOW3, solved through Object Lifecycle 
methods, we need to call it explicitely
		$view->assign('settings', $this->settings); // same with settings 
injection.
	}
	
}

I'm not really happy with this solution, as i had to repeat code that is 
executed before.

The reason, why i had to copy so much code from the controllers 
resolveView-method is, that extbase, if there is no viewfile found, 
instantiates another view-template-class.

Maybe somebody more common with fluid and the MVC package in extbase has 
another, better solution.

regards
Dennis


More information about the TYPO3-project-typo3v4mvc mailing list