[TYPO3-mvc] how to make a controller extension friendly

Martin Kutschker masi-no at spam-typo3.org
Tue Apr 6 21:56:30 CEST 2010


Hi!

While playing with extending extensions with another I noticed that you have to rewrite mayn
functions just to get the right class (for the extending extension).

Here's a way to make extending a controller that works on a repository easy to extend. If the other
extensions uses the same directory layout (and it should) then the extending controller will get the
expected repository (the one belonging to the extending extension).

class Tx_BallroomDancing_Controller_DanceController extends Tx_Extbase_MVC_Controller_ActionController {

	/**
	 * Pattern to build a dance repository.
	 * @var string
	 */
	protected $danceRepositoryNamePattern = 'Tx_ at extension_Domain_Repository_DanceRepository';

	/**
	 * @var Tx_BallroomDancing_Domain_Repository_DanceRepository
	 */
	protected $danceRepository;

	/**
	 * Initializes the current action
	 *
	 * @return void
	 */
	public function initializeAction() {
		// be extension friendly
		$danceRepositoryName = str_replace('@extension',
			$this->request->getControllerExtensionName(),
			$this->danceRepositoryNamePattern
		);
		$this->danceRepository = t3lib_div::makeInstance($danceRepositoryName);
	}
}

Masi


More information about the TYPO3-project-typo3v4mvc mailing list