TYPO3 and SEO since 2011

TYPO3 Extensions and Namespaces

TYPO3 6.0, scheduled for October 2012, will introduce quite some changes under its hood, especially for developers. All PHP classes were migrated to namespaces and by the way most of the classes were renamed and moved to new folders.

What namespace do I use for my TYPO3 Extension?

In advance: The biggest code changes were -at the time writing this- just done two weeks ago and the core team is still very busy to fix the issues that were introduced with the migration. As far as I can tell everything looks like going into the right direction, but it's still possible that there will be changes to the class structure or even a complete revert of the namespace migration until the release of TYPO3 6.0.

At the moment all core classes were moved into system extensions and are now under the namespace \TYPO3\CMS\ExtensionName. The ExtensionName has to be the UpperCamelCase form of the extension key. So the class CssStyledContentController in typo3/sysext/css_styled_content/Classes/Controller/CssStyledContentController.php has the namespace \TYPO3\CMS\CssStyledContent\Controller.

For all other extensions the namespace has to be \Vendor\ExtensionName. Vendor is the supplier of the extension and e.g. can be derived from the name of the developer, a github account or a company or organization name.
Example: The ProductController in EXT:my_shop/Classes/Controller/ProductController.php has the namespace \MyCompany\MyShop\Controller.

When dealing with a class name with namespace the autoloader will resolve it like this:

  • If the namespace starts with \TYPO3\CMS the third segment is assumed to be the ExtensionName
  • Else the second segment is assumed to be the ExtensionName
  • Given the ExtensionName the extension key and the path to the extension can be resolved
  • The rest of the namespace segments applies to the folder structure inside the extension's Classes folder.

Notice: Though it will technically work if you use the \TYPO3\CMS namespace for your own extensions, this namespace is reserved only for the TYPO3 core. You are advised to use your own Vendor namespace.

TYPO3 Extensions and Namespaces

Be social

    Related Topics

  • TYPO3