0

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.

2
  • Did you clear cache after fixing the indentation of your mymodule.routing.yml file? – sonfd Aug 3 '20 at 14:04
  • several times I did. For some reason it still does not work. I also changed the path to '/nothingworks', cleared cache and when I visited I saw page not found. If I again visit /mymodule I get the access denied message – user agent Aug 3 '20 at 17:48

Your Answer

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

Browse other questions tagged or ask your own question.