【问题标题】:The requested controller was unable to dispatch the request请求的控制器无法发送请求
【发布时间】:2017-04-28 11:14:01
【问题描述】:

,我是 Zend 框架的新手,一直在开发一个应用程序,以便我能更熟悉它。
该应用程序具有身份验证和会话处理以及管理员(用户模块)的用户管理。
该应用程序还有一个“模块”模块,其中包含“管理”、“添加”、“查看”、“编辑”和“删除”操作。
我的索引视图按 id 顺序打印出所有模块,但由于模块列表包含 30 多个模块,因此页面最好按模块类别进行过滤。
我的逻辑是在 ModuleController 中创建一个用于过滤的操作函数(所有其他操作都在其中),在“access_filter”数组下的“module.config.php”中声明它:

 'access_filter' => [
    'options' => [
        'mode' => 'restrictive'
    ],
    'controllers' => [
        Controller\IndexController::class => [
            // Allow anyone to visit "index" and "about" actions
            ['actions' => ['index', 'about'], 'allow' => '*'],
            // Allow authorized users to visit "settings" action
            ['actions' => ['settings'], 'allow' => '@']
        ],
        Controller\ModuloController::class => [
            ['actions' => ['admin'], 'allow' => '*'],
            ['actions' => ['admin', 'view', 'view_comu','add','edit','delete'], 'allow' => '@']

        ],
    ]
],

当我尝试访问模块操作时出现此错误提示:
"请求的控制器无法发送请求。

控制器: 应用程序\控制器\模控制器"

我错过了什么吗?

【问题讨论】:

    标签: php zend-framework


    【解决方案1】:

    您可能在配置中的某处缺少另一个 controllers 键(包含控制器容器配置的根 controllers 键)。

    应该是这样的:

    return [
        'controllers' => [
            'factories' => [
                Controller\IndexController::class => Controller\IndexControllerFactory::class,
                Controller\ModuloController::class => Controller\ModuloControllerFactory::class,
            ],
        ],
    ];
    

    【讨论】:

    • 在我的情况下,我忘记在末尾添加 Action 或控制器函数名称
    • @Kamlesh,很乐意为您提供帮助。
    【解决方案2】:

    如果您在地址栏中写入路径如/path/to/controller,并且在设置may_terminate = true 时未指定默认操作,也会出现此错误。将action 添加到路径中,例如/path/to/controller/action,可以解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-09
      • 2018-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多