I was trying to build a small hello world module which has 1 url defined.
Module name : helloworld
url : sayhi
Expected output: A page that says hi
Here is the code that I had based on a couple of tutorials i found about D8 routing and from https://drupal.org/node/1800686
[root]/modules/helloword/helloworld.info.yml
name: Hello World
type: module
description: 'Just Says Hi'
package: Core
version: VERSION
core: 8.x
[root]/modules/helloword/helloworld.module
<?php
/**
* Implements hook_menu
*/
function helloworld_menu() {
$items['sayhi'] = array(
'title' => 'Hello World',
'description' => "Say Hi to All",
'route_name' => 'helloworldhi', // this links the menu item to the route.
'type' => MENU_LOCAL_TASK,
);
return $items;
}
/**
* Implements hook_permission().
*/
function helloworld_permission() {
return array(
'access hi' => array(
'title' => t('Access the page that says hi'),
),
);
}
[root]/modules/helloword/helloworld.routing.yml
helloworldhi:
pattern: '/sayhi'
defaults:
_content: 'Drupal\helloworld\Controller\HelloWorldController::sayHi'
requirements:
_permission: 'access hi'
[root]/modules/helloword/Controller/HelloWorldController.php
<?php
namespace Drupal\helloworld\Controller;