6.6 创建routing.yml文件

routing龢龟龛 https://www.drupal.org/node/2092643

Drupal8齭齩齥齤齢齡齝齚齙齘龢齔齒齏齋

  • hello_world.routing.yml 齁齀URL鼴鼰鼭鼫鼪鼦鼥齩鼡鼝鼚鼘
  • hello_world.links.menu.yml 齁齀齥齤鼑齩鼏齒
  • hello_world.links.action.yml 鼊鼈Drual7齩鼄鼁MENU_LOCAL_ACTION
  • hello_world.links.task.yml 鼊鼈Drupal7齩鼄鼁MENU_DEFAULT_LOCAL_TASK

黛hello_world.routing.yml齭默黗黔黐黎黊齋

hello_world.content:
  path: '/hello'
  defaults:
    _controller: '\Drupal\hello_world\Controller\HelloController::content'
  requirements:
    _access: 'TRUE'
  • path: 鼴齝麹麷齩鼴鼰麶麳齡麯麮麭麫麪
  • _controller: 麩麥鼴齝齩鼴鼰HelloController齩content麡麠
  • requirements: 麟麞麝麙麕麔齚齘麒麑麍麋麊齩麆麄

黛麀鹾鹽鹺齭麶鹹鹸鹶齘鹲鹱PSR-4鹨鹤齩鹽鹺鼏齒/src/Controller麶鹡黛鹞鹽鹺黐鹹鹸鹛鹚鹘龢齔HelloController.php鹔鹒鹎齚齘麀鹾鹊鹆鹂鹁鸾hello world齚鸺齩鸹鹲鸵麶麳齡黛/src/Controller/HelloController.php龢齔齭鹁鸲麯黐黎黊:

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

namespace Drupal\hello_world\Controller;

use Drupal\Core\Controller\ControllerBase;

class HelloController extends ControllerBase {
  public function content() {
    return array(
        '#type' => 'markup',
        '#markup' => $this->t('Hello, World!'),
    );
  }
}

黛url鸀鷼鷻鹁鸲/hello麶鷷鷳鷱鷮鷫鷧Hello,World!鷧齚鸺齩鷣鷟鹔

本书共79小节:

评论 (写第一个评论)