0

In my custom module, ed_helper, I have this ed_helper.routing.yml:

ed_helper.my_page:
  path: '/mypage/page'
  defaults:
    _controller: '\Drupal\ed_helper\Controller\EdHelperController::myPage'
    _title: 'My first page in D8'
  requirements:
    _permission: 'access content'

In ed_helper/src/Controller, I have this EdHelperController.php:

<?php
namespace Drupal\ed_helper\Controller;

use Drupal\Core\Controller\ControllerBase;

/**
 * Utility pages.
 */
class EdHelperController extends ControllerBase {

  /**
   * Returns a simple page.
   *
   * @return array
   *   A simple renderable array.
   */
  public function myPage() {
    return [
      '#markup' => 'Hello, world',
    ];
  }

}

I have confirmed that the module is installed, and I cleared the cache, but am still getting "Page not found" at /mypage/page. What am I missing?

I tried switching the theme to Claro, but I still get "page not found" at my custom route. I also tried uninstalling ed_helper and re-installing it.

My Drupal version is 10.1.

1 Answer 1

0

You can create the same simple hello world custom page with Drush:

drush generate module

Enter a module name mymodule and skip all questions except the one for a controller where you answer yes.

Install the module

drush en mymodule

and then visit www.example.com/mymodule/example to see the controller result.

3
  • This works, but I am still not able to create a custom page in my ed_helper module. Even if I copy and paste the files from the drush-generated mymodule into ed_helper and then change the namespace, filenames, etc, accordingly, it still doesn't work. There must be something wrong with my site. It may be that some of my project files aren't visible to the Docker container.
    – arnoldbird
    Aug 7 at 14:58
  • 1
    Don't change the namespace by hand, enter the real module name when generating the files. You can generate them in a different environment, test them and then copy the entire module directory.
    – 4uk4
    Aug 7 at 15:19
  • The mutagen cache needed to be reset. After deleting and re-creating my Docker containers, the problem is resolved. I'm going to accept your answer because generating a module with Drush does seem like the best way to confirm that there is no issue with Drupal.
    – arnoldbird
    Aug 7 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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