问题
I'm following the Modules, Routes and Controllers tutorial. However, I kept getting "Page not found" regardless of "Clear all cache".
dino_roar.info.yml file:
name: Dino ROAR
type: module
description: "ROAR at you"
package: Custom
core: 8.x
dino_roar.routing.yml
dino_says:
path: /the/dino/says/
defaults:
_controller: Drupal\dino_roar\Controller\RoarController::roar
requirements:
_permission: 'access content'
and src/Controller/RoarController.php file:
<?php
namespace Drupal\dino_roar\Controller;
use Symfony\Component\HttpFoundation\Response;
class RoarController
{
public function roar(){
return new Response('ROOOOAR');
}
}
When accessing through: http://drupal-8.dd:8083/the/dino/says/ I get the page not found error. Any suggestion is much appreciated.
Below is my folder structure:
And this is what it looks when I collapsed the src folder.
回答1:
The main module info yml file has to be named after the following scheme:
module_name.info.yml
So it's dino_roar.info.yml for your module. Also you need to enable your module, but as far as I know when the correct named info yml file is not present Drupal doesn't even know about your module.
Also make sure your folder structure is correct:
dino_roar
--> src
--> Controller
RoarController.php
dino_roar.info.yml
dino_roar.routing.yml
回答2:
Got some help from Shashwat Purav at Drupal.org. Below is the routing file I've changed to that works.
dino_roar.dino_says:
path: /dino/says
defaults:
_controller: '\Drupal\dino_roar\Controller\RoarController::roar'
requirements:
_permission: 'access content'
回答3:
I think it is because of your original routing issue, you should change "path: /the/dino/says/" to "path: /the/dino/says"
after remove the last slash, should be fine .
来源:https://stackoverflow.com/questions/36457473/why-is-my-drupal-8-module-show-page-not-found