knb
knb

Reputation: 9285

typo3: does autoloader only work in root dir of an extension?

I know that I can put a file called ext_autoload.php in the root directory of my typo3 4.7 extension. This will load all classes mentioned in the ext_autoload.php file.

However, when I put an ext_autoload.php file in a subdirectory of a backend module, say myext/mod1 this file ext_autoload.php seems to get ignored.

When I invoke the backend module by clicking on it in the left frame, myext/mod1/index.php is called, but the classes mentioned in the higher-level myext/ext_autoload.php also cannot be found.

Thus, only php files in the root directory of the extension seem to benefit from the autoloading mechanism. Is this correct behaviour?

I have these entries in the error log. (Assuming there aren't any misspellings of class names, of course...)

PHP Fatal error:  Class 'tx_myext_module1' not found in /var/www/typo3-4.7.8/typo3_src-4.7.8/t3lib/class.t3lib_div.php on line 4855, referer: http://.../cms/typo3/backend.php

I think it is inefficient to recursively scan the extension's subdirectories and look for autoloading files in many locations, but still, I didn' find more information on the autoloading mechanism.

This is what the file looks like:

return array(
    'tx_icdpdb_module1' => t3lib_extMgm::extPath('icdp_db', 'mod1/class.tx_icdpdb_module1.php')
);

?>

But ext/myextkey/index.php benefits from it, ext/myextkey/mod1/index.php does not.

I have solved the problem by good-old include()'ing the file containing the class I need.

Upvotes: 0

Views: 593

Answers (1)

Michael
Michael

Reputation: 2331

This work if you provide the "full" path to your files like stated in the docs:

<?php
$extensionPath = t3lib_extMgm::extPath('scheduler');
return array(
    'tx_scheduler_croncmd' => $extensionPath . 'class.tx_scheduler_croncmd.php',
    'tx_scheduler_croncmd_normalize' => $extensionPath . 'Normalize/class.tx_scheduler_croncmd_normalize.php',
);
?>

When you use t3lib_extMgm::extPath() or t3lib_extMgm::extRelPath(), everything should be fine.

Upvotes: 1

Related Questions