0
votes

I'm new to this framework and having a trouble rendering the view. here are my codes. I'm following a tutorial from this site http://zf2.readthedocs.io/en/latest/in-depth-guide/first-module.html. I'm really stuck here all i get is the same error over and over. thanks

module.config.php

 return array(
 // This lines opens the configuration for the RouteManager
'view_manager' => array(
    'template_path_stack' => array(
        __DIR__ . '/../view',
        ),
    ),
 'controllers' => array(
     'invokables' => array(
         'Blog\Controller\List' => 'Blog\Controller\ListController'
     )
 ),
 'router' => array(
     // Open configuration for all possible routes
     'routes' => array(
         // Define a new route called "post"
         'post' => array(
             // Define the routes type to be "Zend\Mvc\Router\Http\Literal", which is basically just a string
             'type' => 'literal',
             // Configure the route itself
             'options' => array(
                 // Listen to "/blog" as uri
                 'route'    => '/blog',
                 // Define default controller and action to be called when this route is matched
                 'defaults' => array(
                     'controller' => 'Blog\Controller\List',
                     'action'     => 'index',
                 )
             )
         )
     )
 ),

);

Edit:

Additional Information: Zend\View\Exception\RuntimeException

Message: Zend\View\Renderer\PhpRenderer::render: Unable to render template "blog/list/index"; resolver could not resolve to a file

module
  Blog
   config
     module.config.php
   src
     Blog
      Controller
       ListController.php
   view
     blog
      list
       index.phtml
   Module.php

Regarding my controller, it only contains this

namespace Blog\Controller;

use Zend\Mvc\Controller\AbstractActionController;

Class ListController extends AbstractActionController
{

}
2
Could you add the entire expcetion message to your question as well as the indexAction of your controller?Fge
I've edited the post. I followed the tutorial step by step but still getting this error.Ron Incarnation
I came looking for solution to a similar error in Mezzio. In my case, it turned out that I forgot to add the ConfigProvider for that module in config.php.GoharSahi

2 Answers

2
votes

The path to your view directory is wrong. You're setting it to __DIR__ . '/../src/view', pointing it to $module/src/view.

In the directory tree you provided, the views are not located in the $module/src directory though but in $module/view/.

Updating the path should do the trick:

'view_manager' => array(
    'template_path_stack' => array(
        __DIR__ . '/../view',
    ),
),

(Notice I removed the src fragment).

0
votes

You can use the below code into module.config.php of the module configuration file

   'view_manager' => array(
        'template_map' => array(
           'layout/blog'           => __DIR__ . '/../view/layout/layout.phtml',
           'blog/list/index' => __DIR__ . '/../view/blog/list/index.phtml',
         ),
        'template_path_stack' => array(
        __DIR__ . '/../view',
        ),
     ),