Я пытаюсь добраться до моего первого контроллера и посмотреть на пользовательский модуль с drupal 8. Я новичок, и это мой первый пользовательский модуль.
my_module.info.yaml, расположенный в / modules /custom / my_module
name: My Own Custom Module
description: A silly example module
type: module
core: 8.x
С этим я смог перейти на свое расширение для активации модуля.
Итак, модуль установлен.
ТеперьЯ хочу попробовать набрать мой первый шаблон ветки
Для этого
my_module.routings.yaml, расположенный в / modules / custom / my_module
my_module.article_list:
path: 'my_module/articles'
defaults:
_controller: '\Drupal\my_module\Controller\ArticleController::page'
_title: "Title routing"
requirements:
_permissions: 'access content'
Мой контроллер находится в / modules / custom / my_module / src / Controller
<?php
namespace Drupal\my_module\Controller;
class ArticleController{
public function page(){
$items = array(
array('name' => 'Article one'),
array('name' => 'Article 2')
array('name' => 'Article 3')
);
return array('#theme' => 'article_list',
'#items' => $items,
'#title' => 'Liste d\'article');
}
}
?>
article-list.html.twig, который находится в / modules / custom / my_module / src / templates
<h4>{{ title }}</h4>
<ul>
{% for article in items %}
<li>{{article.title}}</li>
{% endfor %}
</ul>
my_module.module находится в / modules / custom / my_module
<?php
function my_module_theme($existing, $type, $theme, $path){
return array('article_list' => array('variables' => array('items' => array(), 'title' => '')));
}
?>
Но затем, когда я пытаюсь добраться до своего шаблона, я попадаю на страницу, не найденную
http://localhost:9000/drupal-8.7.8/index.php/my_module/articles
Спасибо за вашу помощь.