[英]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.