[英]ZF2 phprenderer & routing
我正进入(状态
Zend\View\Renderer\PhpRenderer::render: Unable to render template "link-
account-manager/add-accounts/index"; resolver could not resolve to a file
而且我不确定为什么当我希望phprender在linkaccount-manager中查找时,为什么要在link-account-manager中查找。 这是默认行为吗? 我尝试递归搜索“ link-account-manager”,但没有匹配项。
这确实是ZF2的默认行为。 您可以看看\\Zend\\View\\Renderer\\PhpRenderer
和\\Zend\\View\\Resolver\\*
。
模板解析器将驼峰式的Module
或Controller
(LinkAccountManager,AddAccountsController)名称转换为模板路径,例如link-account-manager\\add-accounts\\index.phtml
。
可以在module.config.php
配置一些值:
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'your-custom-template' => __DIR__ . '/../view/your-custom-template.phtml' // e.g. !!
),
'template_path_stack' => array(
__DIR__ . '/../view',
// add custom paths here
),
...
),
此外,您还可以通过视图模型更改模板。 假设您具有文件夹结构,例如“ linkaccount-manager \\ view \\ linkaccountmanager \\”(在默认模块的view文件夹中!),例如:
namespace LinkAccountManager;
public class AddAccountsController extends AbstractActionController
{
public function indexAction()
{
$viewModel = new ViewModel();
...
$viewModel->setTemplate('linkaccount-manager\add-accounts\index');
return $viewModel;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.