I am doing a simple "Hello World" drupal module but it doesn't work.
I have the hello_world.info.yml in drupal/web/modules/custom/hello_world
The modules is installed and working.
Now I added a hello_world.routing.yml with this code:
hello_world.hello:
path: '/hello'
defaults:
_controller:
'\Drupal\hello_world\Controller\HelloWorldController::helloWorld'
_title: 'Our first route'
requirements:
_permission: 'access content'
And a HelloWorldController.php in /src:
namespace Drupal\hello_world\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Controller for the salutation message.
*/
class HelloWorldController extends ControllerBase {
/**
* Hello World.
*
* @return string
*/
public function helloWorld() {
return [
'#markup' => $this->t('Hello World')
];
}
}
When I click on "clear cache" so the routing and the controller are added, I get:
The website encountered an unexpected error. Please try again later.
This does not happen before I added the controller and routing.
Any help?