AnswerBun.com

Custom module is not working

I created custom module to display Hello world text in custom page. I did not install drush and composer in my windows machine as I don’t have admin access. I have pasted my files below:

example.module

<?php

function example_menu() 
{
  // The paths given here need to match the ones in example.routing.yml exactly.
  $items['/mypage/page'] = array(
    'title' => 'First page',
    'description' => 'This is a example page.',
    // The name of the route from example.routing.yml
    'route' => 'example.my_page',
  );
  return $items;
}

example.routing

example.my_page:
  path: '/mypage/page'
  defaults:
    _controller: 'DrupalexampleControllerExampleController::mypage'
    _title: 'Hello world'
  requirements:
    _permission: 'access content'

src/Controller/ExampleController.php

<?php

namespace DrupalexampleController;

//use DrupalCoreControllerControllerBase;

class ExampleController 
{
    public function myPage() 
    {
        $element = array('#markup' => 'Hello world!');
        return $element;
    }
}

And I have example.info file as well and the module is enabled. When I run the controller, it says page not found. Can anyone tell me that Am I missed anything in the code?

Drupal Answers Asked by TS Guhan on December 30, 2020

1 Answers

One Answer

hook_menu doesn't exist anymore in D8. Instead use a example.links.menu.yml file.

example.my_page:
  title: 'First page'
  description: 'yout description'
  route_name: example.my_page

Answered by Drupal de Comptoir on December 30, 2020

Add your own answers!

Related Questions

“&” displaying as “&”

1  Asked on February 28, 2021 by mohk

     

Confirmation pop up on login submit

1  Asked on February 22, 2021 by vipin-p

   

Override a node page of specific content with views page

1  Asked on February 21, 2021 by hkguile

     

Hide Alt and Title for image field

2  Asked on February 20, 2021 by moto

       

How do I update from 9.0.10 to 9.1.0?

1  Asked on February 19, 2021 by user101999

   

Adding fields to content type edit form (not to the node itself)

1  Asked on February 18, 2021 by chris-riddell

 

Uploaded images in theme settings is going to be lost

3  Asked on February 13, 2021 by saidbakr

   

How to delete a large amount of nodes effeciently during cron?

1  Asked on February 12, 2021 by athakhan

   

Composer updates .htaccess file when updating

3  Asked on February 11, 2021 by albertski

   

How to print the Views title in page.tpl.php?

3  Asked on February 10, 2021 by szymon-panecki

   

May I use Bootstrap-CDN on Subtheme for production site?

1  Asked on February 7, 2021 by leelandra

     

Alter Webform email body

1  Asked on February 6, 2021 by lus

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.