0
votes

I have (simplified) two modules, Application and Admin. I have worked on the Admin module for a while now and started with Application. Both the modules feature a controller named UsersController.

Now as I started to make the Application and created some routes and actions, my Admin module broke. The error I got when trying to open any admin page everywhere was similar to

Unable to render template "application/users/index"

According to the docs, the first part of the template path is taken from the namespace of the calling controller. But ever since I created the directory module/Application/view/application/users/, it tries to take all the Admin\Controller\UsersController templates from there, without regard to the namespace.

How can I make Zend to use the namespace again, without having to force the template file in the action every time?

(Using Zend 2.1.3)

2

2 Answers

1
votes

The problem here was that I used the same aliases for Controller names in more than one module. So I changed their names like this:

'controllers' => array(
    'invokables' => array(
        'AdminIndex' => 'Admin\Controller\IndexController',
    ),
),

The other module config used the same names and thus just overrode the ones from my Admin module.

0
votes
namespace Admin;

class Module
{
    public function init($moduleManager)
    {
        $sharedEvents = $moduleManager->getEventManager()->getSharedManager();
        $sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e) {
            $actionName = $e->getRouteMatch()->getParam('action');
                $controller = $e->getTarget();
                $controller->layout(__DIR__ . "/Application/view/application/user/$actionName");
        }, 100);
    }
}