En ZF1 utilizamos parcial en el archivo algo como eso layout.phtmlCómo utilizar el parcial en zendframework2
$this->partial('header.phtml', array('vr' => 'zf2'));
¿Cómo podemos hacer lo mismo en ZF2?
En ZF1 utilizamos parcial en el archivo algo como eso layout.phtmlCómo utilizar el parcial en zendframework2
$this->partial('header.phtml', array('vr' => 'zf2'));
¿Cómo podemos hacer lo mismo en ZF2?
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 archivo de view_manager module.config.php.
'layout/header' => __DIR__ . '/../view/layout/header.phtml',
después de añadir Parece que este
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',
),
),
);
Como ya se ha indicado en la respuesta aceptada, puede utilizar
echo $this->partial('layout/header', array('vr' => 'zf2'));
pero luego se va a definir en su layout/header
module.config .php.
Si no quiere saturar su template_map
, se puede utilizar una ruta relativa basado en template_path_stack
para que apunte directamente a su parcial.
Supongamos que ha definido:
'view_manager' => array(
/* [...] */
'template_path_stack' => array(
'user' => __DIR__ . '/../view' ,
),
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
),
);
en su module.config.php y su listsnippet.phtml radica en .../view/mycontroller/snippets/listsnippet.phtml
, entonces puede utilizar el código siguiente:
echo $this->partial('mycontroller/snippets/listsnippet.phtml', array('key' => 'value'));
pasar todas las variables de la vista al parcial: 'echo $ this-> partial ('layout/header', $ this-> viewModel() -> getCurrent() -> getVariables());' – davmor
Tenga en cuenta que '$ this-> viewModel() -> getCurrent() -> getVariables() 'devuelve un [ArrayObject] (http://php.net/manual/en/class.arrayobject.php). – davmor
Para combinar datos adicionales, array_merge funciona: echo $ this-> partial ('mypartial', array_merge ($ this-> viewModel() -> getCurrent() -> getVariables(), [moredata])); – Killan