2012-06-05 29 views
11

Tengo algo como esto para mi estructura de directorios en el interior de un módulo:¿Cómo Zend Framework 2 representa parciales dentro de un módulo?

Api 
├── Module.php 
├── config 
│   └── module.config.php 
├── src 
│   └── (..etc ..) 
└── view 
    ├── api 
    │   └── api 
    │    └── index.phtml 
    └── partial 
        └── test.phtml 

Entonces, estoy haciendo esto:

<?= $this->partial('partial/test.pthml', array()); ?> 

Sin embargo, me sale:

05-Jun-2012 14:56:58] PHP Fatal error: Uncaught exception 'Zend\View\Exception\RuntimeException' with message 'Zend\View\Renderer\PhpRenderer::render: Unable to render template "partial/test.pthml"; resolver could not resolve to a file' in /Users/jeff/web/n/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php:463

Donde debería ir mis parciales?

+1

La estructura de directorios es correcta y su ayudante de vista parcial está configurado correctamente. Solo asegúrate de tener ''template_path_stack' => array ('user' => __DIR__. '/../ view')' agregado a tu archivo 'module.config.php' y deberías estar bien. –

Respuesta

21

esto se puede lograr mediante

echo $this->partial('layout/header', array('vr' => 'zf2')); 

se puede acceder a la variable en la vista usando

echo $this->vr; 

no se olvide de añadir siguiente línea en su view_manager del archivo module.config.php.

'layout/header'   => __DIR__ . '/../view/layout/header.phtml', 

después de añadir que se parece a esto

return array( 

'view_manager' => array(
     'template_path_stack' => array(
      'user' => __DIR__ . '/../view' , 
     ), 
     'display_not_found_reason' => true, 
     'display_exceptions'  => true, 
     'doctype'     => 'HTML5', 
     'not_found_template'  => 'error/404', 
     'exception_template'  => 'error/index', 
     'template_map' => array(
      'layout/layout'   => __DIR__ . '/../view/layout/layout.phtml', 

      'layout/header'   => __DIR__ . '/../view/layout/header.phtml',    

      'error/404'    => __DIR__ . '/../view/error/404.phtml', 
      'error/index'    => __DIR__ . '/../view/error/index.phtml', 
     ), 


    ),  

); 
+0

En mi módulo, uso lo siguiente: $ this-> partial ('{module}/{controller}/{filename} .phtml', array ('var_name_in_partial' => $ data)); –

+0

Ojalá pudiera votar dos veces. Muy buena explicación. –

Cuestiones relacionadas