dpgui8229808 2018-12-04 10:46
浏览 198
已采纳

没找到Drupal 8模块路由页面?

I have a simple question, I want Drupal to route this page but keep getting this error:

"The website encountered an unexpected error. Please try again later."

The drupal error log displays this :

"InvalidArgumentException: Class "\Drupal\dblogin\Controller\DbloginController::reddb" does not exist. in Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition() (line 24 of C:\drupal_sites\drupal-8.6.2\core\lib\Drupal\Core\DependencyInjection\ClassResolver.php)."

The code I have implemented for this is:

dblogin.reddb:
  path: /admin/reddb
  defaults:
    _title: 'DBlogin'
    _form: '\Drupal\dblogin\Controller\DbloginController::reddb'
  requirements:
    _permission: 'access content'

and in \src\Controller\DbloginController.php

<?php
namespace Drupal\dblogin\Controller;
use Drupal\Core\Controller\ControllerBase;

class dbloginController extends ControllerBase {

public function reddb() {
      $build = [
        '#markup' => $this->t('DB Login'),
      ];
      return $build;
}
/**
 * replacement process callbacks.
 */
}
?>

I have also tried to just make it return "hello", but to no avail.

<?php
namespace Drupal\dblogin\Controller;
use Drupal\Core\Controller\ControllerBase;

class dbloginController extends ControllerBase {

    public function reddb() {
        return "hello";
    }
    /**
       * replacement process callbacks.
    */
}
?>

Could anyone help me out here? Thanks in advance!

  • 写回答

3条回答 默认 最新

  • drahywu329376 2018-12-11 11:23
    关注

    error: _form: '\Drupal\dblogin\Controller\DbloginController::reddb'

    It must be:

    _controller: '\Drupal\dblogin\Controller\DbloginController::reddb'

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 爬取豆瓣电影相关处理
  • ¥15 手机淘宝抓清除消息接口
  • ¥15 C#无selenium
  • ¥15 LD衰减计算的结果过大
  • ¥15 用机器学习方法帮助保险公司预测哪些是欺诈行为
  • ¥15 计算300m以内的LD衰减
  • ¥15 数据爬取,python
  • ¥15 怎么看 cst中一个面的功率分布图,请说明详细步骤。类似下图
  • ¥15 为什么我的pycharm无法用pyqt6的QtWebEngine
  • ¥15 FOR循环语句显示查询超过300S错误怎么办