How does Laminas generate the path to templates?

Hi all,

today, I’ve run into a problem that I don’t understand.

I have a small application with a number of controllers.
Usually all my templates reside in view/foo/bar/action.phtml where foo is my module’s name, bar is the route and action is the method called on the controller with slight modifications.

So, I have templates like member/member/index.phtml or member/password/requests.phtml within my view directory.

But now I get an exception that looks strange to me:
Laminas\View\Renderer\PhpRenderer::render: Unable to render template "admin/group/group/list-groups"; resolver could not resolve to
Why do I have group twice in this path?
The configuration does not differ from any other route, but when I start debugging, the ViewModel always contains this as the template path.

So my question ist:
Why (under which circumstances) does this happen and how can I change this behavior?
As I’m not able to understand what’s going on there, it looks somehow erratic to me :frowning:

Thanks for any help,
Gerrit

Hi @gbeine,

I don’t know why.
Do you have in module.config.php template_path_stack right?

'view_manager' => array(
    'template_map' => include __DIR__ . '/template_map.config.php',
    'template_path_stack' => array(
        __NAMESPACE__ => __DIR__ . '/../view'
     )
),

Also in view/foo/bar/action.phtml

  • foo - module
  • bar - controller
  • action.phtml - action

Thank you @tomstryja!
Yes, the view_manager configuration is there:

    'view_manager' => [
        'display_not_found_reason' => true,
        'display_exceptions'       => true,
        'doctype'                  => 'HTML5',
        'not_found_template'       => 'error/404',
        'exception_template'       => 'error/index',
        'template_map' => [
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
            'error/404'               => __DIR__ . '/../view/error/404.phtml',
            'error/index'             => __DIR__ . '/../view/error/index.phtml',
        ],
        'template_path_stack' => [
            __DIR__ . '/../view',
        ],
    ],

It’s the same in all other modules where it works properly.
And yes, the directory with the files is there, too.
I’m just confused why the controller’s name is twice in the generated template path.

Is it routing to controller action correctly? When you var_dump() something in action do you see result?

1 Like

Please check the namespace and classname of your controller, maybe you have Admin\Controller\Group\GroupController instead of Admin\Controller\GroupController.

1 Like

Thanks a lot - that was the hint!
I used namespaces in a DDD-style, so, the GroupController was in the namespace Group, not Controller.
After moving it to the namespace (and directory) Controller, it works perfectly.

Good to know that some principles depend on the namespaces.

Best regards
Gerrit