Search code examples
phpzend-framework

The requested controller was unable to dispatch the request


Hi, im newbie in Zend Framework and have been developing a Application so that i can get more familiar with it.
The Application has Authentication and Session treatment plus a Users Management for the admin(User Module).
The Application also has a module for "Modules" with the actions "admin", "add", "view", "edit" and "delete".
My index view prints out all modules order by id but since the list of modules contains more than 30 modules, it would be better for page to have a filtering by Module Category.
My logic was to create a action function for filtering in the ModuleController(where all the other actions are), declare it in my "module.config.php" under the "acess_filter" array :

 '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' => '@']

        ],
    ]
],

When i tried to access the module action this error prompt:
"The requested controller was unable to dispatch the request.

Controller: Application\Controller\ModuloController "

Did i miss something?


Solution

  • You are probably missing another controllers key somewhere in your configuration (the root controllers key that contains the configuration for the controllers container).

    It should look like this:

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