I'm trying to create a new module with a routing file pointing to a controller. But i get the following error in my logs
ReflectionException: Class \Drupal\glue\Controller\GlueController does not exist in ReflectionMethod->__construct() (line 128 of /home/vagrant/Projects/neut-business-website/core/lib/Drupal/Core/Entity/EntityResolverManager.php).
glue.routing.yml:
hello_world:
path: '/hello-world'
defaults:
_controller: '\Drupal\glue\Controller\GlueController::helloWorldPage'
requirements:
_permission: 'access content'
With following controller
project_folder/modules/glue/src/Controller/GlueController
<?php
namespace Drupal\glue\Controller;
class GlueController {
public function hellowWorldPage() {
return [
'#markup' => t('<p>Hello world</p>')
];
}
}
I faced a similar error while creating my first drupal 8 module. I couldn't figure out the error in your case but would like to share the fault in my case.
Somehow, myController.php file was placed outside the
/my_module/src/Controller/
folder.
Moving the file to the proper directory solved the problem.
May be this saves somebody's time someday somewhere :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With