Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal Class not found

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>')
    ];
  }
}
like image 539
Ian Droogmans Avatar asked Jul 20 '26 11:07

Ian Droogmans


1 Answers

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 :)

like image 138
Sonam Singh Avatar answered Jul 22 '26 02:07

Sonam Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!