How does Zend Framework 2 render partials inside a module?

前端 未结 2 1856
有刺的猬
有刺的猬 2021-02-08 06:36

I\'ve got something like this for my directory structure inside a module:

Api
├── Module.php
├── config
│   └── module.config.php
├── src
│   └── ( ..etc ..)
└──         


        
2条回答
  •  离开以前
    2021-02-08 07:07

    this can be achieved by

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

    you can access the variable in view using

    echo $this->vr;
    

    don't forget to add following line in your view_manager of module.config.php file.

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

    after adding it looks like this

    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',
            ),
    
    
        ),    
    
    );
    

提交回复
热议问题