-1

I did a custom module, but i can't see the page with the URL : Page not found. I can install the module and activiate, but i can't go on the page.

This is the code :

hello_world.hello_world:
  path: '/helloworld'
  defaults:
    _controller: 'Drupal\hello_world\Controller\HelloWorldController::helloWorld'
    _title: 'Hello World'
  requirements:
    _permission: 'access content'

name: Hello World
core: 8.x
type: module
package: Tutos
description: Mini module test Drupal 8

<?php
/**
 * @file
* Contains \Drupal\hello_world\Controller\HelloWorldController.
*/

namespace Drupal\hello_world\Controller;
use Drupal\Core\Controller\ControllerBase;

/**
 * Controller routines for hello_world module routes.
 */
class HelloWorldController extends ControllerBase {

  /**
   * Return the 'Hello World' page.
   *
   * @return string
   *   A render array containing our 'Hello World' page content.
   */
  public function helloWorld() {
    $output = array();

    $output['hello_world'] = array(
        '#markup' => $this->t('Hello World!'),
    );
    return $output;
  }
}
1
  • Looks all fine to me, is your controller class in the right place? You might want to share the whole folder somehow, e.g. as a github project.
    – Berdir
    Feb 9, 2016 at 23:48

1 Answer 1

-2

You may need a leading \ for the controller definition.

1
  • Yes, according to current Drupal coding standards the line in the routing file should be _controller: '\Drupal\hello_world\Controller\HelloWorldController::helloWorld' HOWEVER it will work without the leading backslash - this is NOT an answer to why the code doesn't work.
    – anonymous
    Jan 28, 2021 at 5:20

Your Answer

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

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