ZF2 "Unable to render template" Zend looks in wrong directory
php, zend-framework2
Solution
The complete path cannot be resolved by zf2. The viewManager is using your template pathStack to find the relative view. In your example, the viewManager is looking for this file : DIR . '/../view/authentication/auth/login.phtml
In other way, you can add to your viewManager a templateMap like this :
'view_manager' => array(
'template_map' => array(
'authentication/auth/login' => __DIR__ . '/../view/where/you/want.phtml',
)
);
Problem
I've got a strange situation... After the creation of the ZF2 SkeletonApplication I created an extra Module called Authentication with an AuthController and a LoginAction also in the view directory "authentication/auth" i placed a login.phtml. When i run the app i get an error ``` Zend\View\Renderer\PhpRenderer::render: Unable to render template "authentication/auth/login"; resolver could not resolve to a file ``` The strange thing is that when I place the complete folder "authentication/auth/login.phtml" in the Standard Application Module View Folder it finds it. So Zend is looking in the wrong directory. This is my module.config.php (Authentication Module). ``` return array( 'router' => array( 'routes' => array( 'authentication' => array( 'type' => 'Zend\Mvc\Router\Http\Literal', 'options' => array( 'route' => '/authentication/login', 'defaults' => array( 'controller' => 'Authentication\Controller\Auth', 'action' => 'login', ), ), ), ), ), 'controllers' => array( 'invokables' => array( 'Authentication\Controller\Auth' => 'Authentication\Controller\AuthController', ), ), 'viewmanager' => array( 'template_path_stack' => array( 'authentication' => __DIR__ . '/../view', ), ) ); ``` This is the AuthController ``` namespace Authentication\Controller; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; class AuthController extends AbstractActionController { public function loginAction() { return new ViewModel(); } } ``` I hope someone can point me in the right direction.