如何实施路线?


7

如何在Drupal 8中实现最基本的路线?我必须写哪些文件,我需要实现哪些类?

Answers:


11

在Drupal 8中实施最基本的路线要求:

  • 包含路由定义的文件(helloworld.routing.yml)

    helloworld.hi:
      pattern: '/helloworld'
      defaults:
        _controller: '\Drupal\helloworld\Controller\HelloWorldController::hi'
      requirements:
        _permission: 'access content'
    
  • 返回渲染数组或字符串的控制器类(src / Controller / HelloWordCOntroller.php)

    namespace Drupal\helloworld\Controller;
    
    class HelloWorldController {
      function hi() {
        return 'Hello world!';
      }
    }
    

这相当于Drupal 7中的MENU_CALLBACK。与Drupal 7不同,实现本地任务或执行本地操作需要添加其他文件,Drupal 7的本地选项卡将使用用于的相同钩子来实现MENU_CALLBACK

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.