TransWikia.com

Custom module is not working

Drupal Answers Asked by TS Guhan on December 30, 2020

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?

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!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP