jef*_*lez 11 php zend-framework2
我在模块中的目录结构中有这样的东西:
Api
??? Module.php
??? config
? ??? module.config.php
??? src
? ??? ( ..etc ..)
??? view
??? api
? ??? api
? ??? index.phtml
??? partial
??? test.phtml
Run Code Online (Sandbox Code Playgroud)
然后,我这样做:
<?= $this->partial('partial/test.pthml', array()); ?>
Run Code Online (Sandbox Code Playgroud)
但是,我得到:
2012年6月5日14:56:58] PHP致命错误:未捕获异常'Zend\View\Exception\RuntimeException',消息'Zend\View\Renderer\PhpRenderer :: render:无法渲染模板"partial/test.pthml "; 解析器无法解析为/Users/jeff/web/n/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php:463中的文件
凡应我的谐音去?
Dev*_*per 22
这可以通过实现
echo $this->partial('layout/header', array('vr' => 'zf2'));
Run Code Online (Sandbox Code Playgroud)
您可以使用查看视图中的变量
echo $this->vr;
Run Code Online (Sandbox Code Playgroud)
不要忘记在module.config.php文件的view_manager中添加以下行.
'layout/header' => __DIR__ . '/../view/layout/header.phtml',
Run Code Online (Sandbox Code Playgroud)
添加后它看起来像这样
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',
),
),
);
Run Code Online (Sandbox Code Playgroud)