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

评论 (写第一个评论)