3
votes

I have an extension located under ext/my_ext. My viewhelper is located under /ext/my_agarar_template/Classes/ViewHelpers/TestViewHelper.php.

when I try to call my viewhelper, my template says that my class doesn't exist.

My template looks like this:

{namespace p=ext\my_ext\ViewHelpers}
h1>ViewHelper-Test</h1>
<p><p:HelloWorld /></p>

Here is my error message:

Oops, an error occurred! Fluid parse error in template Standard_action_my_ext_slide_db2750e6ca45c0832d4fc312cf0618afbe9329d0, line 11 at character 5. Error: The ViewHelper "" could not be resolved. Based on your spelling, the system would load the class "ext\my_ext\ViewHelpers\TestViewHelper", however this class does not exist. (error code 1407060572). Template source chunk: More information regarding this error might be available online.

I load it via Composer and my PSR-4 looks like this:

"autoload": {
    "psr-4": {
      "myext\\MyExt\\": "web/typo3conf/ext/my_ext/Classes"
    }
}

I don't know why my classes aren't loading.

Hope someone can help me,

thanks in advance.

1
You should post your template where you are trying to use the viewhelper. Also you should post the exact error message you see. - Mathias Brodala
Your psr-4 declaration is wrong, this should be "myext\\MyExt\\": "Classes". After the change you have to run composer dump-autoload - Simon Gilli

1 Answers

0
votes

As mentioned, your autoload section looks weird in composer.json. However, your autoloading seems to be working, otherwise you would probably not get this far, I guess.

I would check the following:

  • check composer.json autoload section
  • check spelling of files and class names: The ViewHelper class should be in Classes/ViewHelpers and should be the same filename + classname HelloWorldViewHelper.php and class HelloWorldViewHelper (this looks ok from your sample code)
  • is namespace correct in ViewHelper class?
  • just to be sure: Is your template code valid XML? (there is a '<' missing in h1)
  • why is the class called TestViewHelper but the name is HelloWorld? Should be HelloWorldViewHelper and <p:helloWorld>. Watch for upper / lower case.
  • clear entire cache (again) and dump autoload (again) composer dump-autoload
  • you can check the file vendor/composer/autoload_psr4.php to see if the mapping namespace to filename is correct.

In general, I would stay away from extension keys with underscores ('_'). This is also recommended in the documentation. The thing is: The spelling, using correct upper and lowercase, vendor name or not etc. can be challenging enough. Using underscore in extension keys makes this even more difficult. Not a problem if you know the rules or know where to look but poses unnecessary difficulties for beginners.

Tip: Look in bootstrap_package. It has an underscore in the name and contains ViewHelpers.