ZF2 Modules in Subfolders

due to a large project which will be realised in ZF2, I came across the following problem and I seem to misunderstand the handling of namepaces.

The project will have a lot of modules of similar groups. I will have 4 groups (A, B, C, D) and all modules in group A will deal with input for example. In order to make sure, that we do not end up with a folder containing 200 modules, we want to group the ones that belong together for reasons of cleanliness.

So basically we wish for the following structure:

  /MainApplication <- accesses all modules

I already adjusted the namespace to groupA\Module1, adjusted the routes accordingly and all the paths seem to be correct and yet I get errors saying that for example the template files cannot be accessed.

Can you give me a hint what you would have to pay attention to when you move a model from /modules/module1 to /modules/subfolder/module1.

What I tried
Changed all namespaces to: -------------------------------------------

/config/application.php: ---------------------------------------------
    'modules' => array(

/module/groupa/Module.php: -------------------------------------------
    'route'    => '/',
    'defaults' => array(
        'controller' => 'groupa\module1\Controller\Index',
        'action'     => 'index',
'controllers' => array(
    'invokables' => array(
        'groupa\module1\Controller\Index' => 'groupa\module1\Controller\IndexController'

Currently, the module is not supposed to do much. Just showing the index.phtml template. The error I get is the following:

Fatal error: Uncaught exception 'Zend\View\Exception\RuntimeException' with message 'Zend\View\Renderer\PhpRenderer::render: Unable to render template "groupa/index/index"; 

resolver could not resolve to a file' in /Users/xxx/Sites/zf2helloworld/vendor/Zend/View/Renderer/PhpRenderer.php:461 

Stack trace: 
#0 /Users/xxx/Sites/zf2helloworld/vendor/Zend/View/View.php(203): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel)) 
#1 /Users/xxx/Sites/zf2helloworld/vendor/Zend/View/View.php(231): Zend\View\View->render(Object(Zend\View\Model\ViewModel)) 
#2 /Users/xxx/Sites/zf2helloworld/vendor/Zend/View/View.php(196): Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel)) 
#3 /Users/xxx/Sites/zf2helloworld/vendor/Zend/Mvc/View/Http/DefaultRenderingStrategy.php(128): Zend\View\View->render(Object(Zend\View\Model\ViewModel)) 
#4 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent)) 
#5 /Users/xxx/Sites/zf2helloworld/vendor/Zend/EventManager/Ev in /Users/xxx/Sites/zf2helloworld/vendor/Zend/View/Renderer/PhpRenderer.php on line 461

Am I missing the obvious? Why can the template not be found? I echoed back the 'template_path_stack' and it seems to be correct:


I am aware of the reusability of modules and such. We would still love to group modules that belong together into the same folder and preferably access them via the proper URL (groupname/module).

Thank you for your time!


First of all, as per PSR-0 standard your classnames must have the following structure: \<Vendor Name>\(<Namespace>\)*<Class Name>. Meaning that your module name should be <Vendor Name>\<Module\Name>

As for template name, by default FQCN of controller is converted to template like this First namespace/controller class name/controller action name Meaning your Groupa\Module1\Controller\IndexController controller will give you template name groupa/index/index(and not groupa/module1/index/index as you might expect) which will be resolved to file groupa/index/index.phtml in paths defined in template_path_stack

This is default behaviour and it cannot be changed without backwards compatibility break. To mitigate that since zf2.3 there is new setting that will allow you to use modules the way you want. It is controller_map under view_manager config section.

How to use that you can read here: https://github.com/zendframework/zf2/pull/5670

'view_manager' => array(
    'controller_map' => array(
        // Groupa\Module1\Controller\IndexController -> groupa\module1\index\index
        // -> module/Groupa/Module1/view/groupa/module1/index/index.phtml
        'Groupa\Module1' => true,

Need Your Help

How to preserve punctuation marks in Scikit-Learn text CountVectorizer or TfidfVectorizer?

scikit-learn nltk

Is there any way for me to preserve punctuation marks of !, ?, " and ' from my text documents using text CountVectorizer or TfidfVectorizer parameters in Scikit-Learn?

CakePHP 3, display current date

php date cakephp cakephp-3.0

I´ve read the documentation of CakePHP 3: http://book.cakephp.org/3.0/en/core-libraries/time.html#dates