[TYPO3-dev] BE module _DISPATCH - BACK_PATH doesn't work with symlinked core
Helmut Hummel
helmut.hummel at typo3.org
Fri Aug 30 13:32:27 CEST 2013
Hi Jan,
On 28.08.13 12:56, Jan Bednarik wrote:
> I have changed CoolUri's BE modules to be _DISPATCH and I use this code
> to include necessary classes:
This is a good thing.
> require_once $BACK_PATH . t3lib_extMgm::extRelPath('cooluri') .
> 'cooluri/manager/linkmanager.Main.php';
$BACK_PATH contains the *relative* path to the typo3 directory of the
TYPO3 sources.
If you use _DISPATCH then, your module is called from mod.php which is
inside the mod.php directory, so $BACK_PATH is always an empty string.
If you want to require own classes, never use $BACK_PATH but
t3lib_extMgm::extPath('cooluri') which returns the absolute path to your
extension. Thus the require statement should always look like this:
require_once t3lib_extMgm::extPath('cooluri') .
'manager/linkmanager.Main.php';
A better (future proof) approach would be to include all your classes in
a ext_autoload.php file, which the extension extdeveval can
automatically create for you. Then you do not need any requires at all.
> So what is the correct approach? For required I could use
> dirname(__FILE__), but this won't work when I e.g. include CSS:
>
> $this->pageRenderer->addCssFile($BACK_PATH .
> t3lib_extMgm::extRelPath('cooluri') . 'mod1/style.css');
As said above, $BACK_PATH is empty if you use the module dispatcher and
if not includes the relative path tho the typo3 directory of the TYPO3
sources. $BACK_PATH is of no use, if you want to add your extension
resources for rendering. You can just use
$this->pageRenderer->addCssFile('' . t3lib_extMgm::extRelPath('cooluri')
. 'mod1/style.css');
because the page renderer accepts paths relative to document root.
HTH
Kind regards,
Helmut
--
Helmut Hummel
Release Manager TYPO3 6.0
TYPO3 Core Developer, TYPO3 Security Team Member
TYPO3 .... inspiring people to share!
Get involved: typo3.org
More information about the TYPO3-dev
mailing list