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小节:

评论 (写第一个评论)