请求的控制器无法分派请求

时间:2017-04-28 11:14:01

标签: php zend-framework

,我是Zend Framework的新手,并且正在开发一个应用程序,以便我可以更熟悉它。
应用程序具有身份验证和会话处理以及管理员(用户模块)的用户管理 该应用程序还有一个“模块”模块,其操作为“admin”,“add”,“view”,“edit”和“delete”。
我的索引视图按ID排序打印所有模块,但由于模块列表包含30个以上的模块,因此页面按模块类别进行过滤会更好。
我的逻辑是在ModuleController中创建一个用于过滤的动作函数(所有其他动作都在其中),在“acess_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' => '@']

        ],
    ]
],

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

控制器:     Application \ Controller \ ModuloController“

我错过了什么吗?

2 个答案:

答案 0 :(得分:1)

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

它应该是这样的:

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

答案 1 :(得分:0)

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

相关问题