简体   繁体   中英

TYPO3 does not autoload PHP files in Classes folder

Hi I started working with TYPO3 a few weeks ago and I wanted to run my own PHP script when the website starts. So I put my PHP file called "Testfile.php" into typo3conf/ext/myextension/Classes folder. My code:

namespace Example\MyExtension;


class Testfile
  {
       public function doStuff() {
       return 'I did stuff';
       }
  }

After that I put this typoscript code into my page at the backend.

page = PAGE
page.10 = USER
page.10.userFunc = Example\MyExtension\Testfile->doStuff

After refreshing my page I expected to get the text "I did stuff" but got only a blanc screen.

Can you explain me what I did wrong?

您是否在composer.json中声明了自动加载指令,并解雇了composer du或其他会重新生成类加载器文件的文件?

For own extensions that are not required by composer you have to add the base of your extension classes to the autoload section of the composer.json in your root path, eg

"autoload": { "psr-4": { Example\\\\MyExtension\\\\": "public/typo3conf/ext/my_extension/Classes", } }

After that call composer dumpautoload and you should be fine.

Are you in composer mode ???

In composer mode adding the autoload part in composer.json as Chris described above should work, but if you are note in composer mode I don't know how you can add php code since includeLibs is gone

Declare "atoload" in you composer then run composer dumpautoload

Goodluck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM