User login

Error when Drupal 8 class file is misplaced

The error is pretty straightforward but the sheer confusion of where to place class files in your module (first off, yes, they do go in your module) might make this a pretty commonly googled error.

Drupal may give an error like this:

Error
The website has encountered an error. Please try again later.

Look in your logs for more detail:

tail -f -n100 /var/log/apache2/error.log

Here's the key problem:

[Fri Jun 06 18:05:01.084354 2014] [:error] [pid 12348] [client 127.0.0.1:41897] Uncaught PHP Exception InvalidArgumentException: "Class "\\Drupal\\testexample\\Controller\\TestexampleController" does not exist." at /home/ben/code/drupal/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php line 29

Solution, in my case, i had to move the controller class file in my module from the incorrect location src/Controller/Testexample/TestexampleController.php to the correct location (without the extra nesting of the module name) src/Controller/TestexampleController.php.

Searched words: 
Uncaught PHP Exception InvalidArgumentException Class Drupal does not exist drupal/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php class .php library file doesn't exist

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.