3

I have created a module called dino_roar, whose job is to create a web page. So i have created a dino_roar.routing.yml file which contains this:

dino_says:
  path: /the/dino/says
  defaults:
    _controller: Drupal/dino_roar/Controller/RoarController::roar
  requirements:
    _permission: 'access content'

Next i have created a PHP class called RoarController, which contains this:

<?php

namespace Drupal\dino_roar\Controller;

use Symfony\Component\HttpFoundation\Response;

class RoarController {
  public function roar() {
    return new Response('ROOOOOOAR!');
  }
}

Here's a screenshot of my module's file tree:

dino_roar file tree

When i empty the cache, i get the following error:

ReflectionException: Class Drupal/dino_roar/Controller/RoarController[error]
does not exist in
/Users/victor/Sites/practice/core/lib/Drupal/Core/Entity/EntityResolverManager.php:123
Stack trace:
#0
...

I have followed exactly what they say in this tutorial, but it doesn't work.

Is my namespace wrong, or what can it be?

2

You need to use back slashes in your _controller definition in your routing.yml. Like:

defaults:
    _controller: Drupal\dino_roar\Controller\RoarController::roar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.