I have a custom module with machine name "mymodule". The mymodule.info.yml file looks like this:
name: My module
type: module
description: 'My first drupal module'
core: 8.x
Then I have a src/Controller/FirstController.php which looks like:
<?php
namespace Drupal\mymodule\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Defines FirstController class.
*/
class FirstController extends ControllerBase {
/**
* Display the markup.
*
* @return array
* Return markup array.
*/
public function content() {
return [
'#type' => 'markup',
'#markup' => $this->t('Hello, World!'),
];
}
}
Finally, I have mymodule.routing.yml that looks like:
mymodule.content:
path: '/mymodule'
defaults:
_controller: '\Drupal\mymodule\Controller\FirstController::content'
_title: 'My first route'
requirements:
_permission: 'access content'
When I go to the url /mymodule, I get Access Denied. How can I fix the permission denied?
I saw a similar issue here but the answer does not seem to work for me.