我创建了一个简单的用户模块,有3个视图(索引,登录,注册)。我试图将它们映射到具有以下代码的用户模块中的IndexController。代码正在运行,没有任何错误,但是没有显示TEMPLATES
控制器代码位于:User'src'users'Controllers'IndexController
namespace Users'Controller;
use Zend'Mvc'Controller'AbstractActionController;
use Zend'View'Helper'ViewModel;
class IndexController extends AbstractActionController
{
public function indexAction()
{
$view = new ViewModel();
return $view;
}
public function registerAction()
{
$view = new ViewModel();
$view->setTemplate('users/index/new-user.phtml');
return $view;
}
public function loginAction()
{
$view = new ViewModel();
$view->setTemplate('users/index/login');
return $view;
}
}
View中的模板是
用户'查看'指数' index.phtml
<h1>Welcome to Users Module</h1>
<a href="/users/index/login">Login</a>
<br> <br>
<a href="/users/index/register">New User Registration</a>
用户'查看'指数' login.phtml
<h2> Login </h2>
<p> This page will hold the content for the login form </p>
<a href="/users"><< Back to Home</a>
用户'查看'指数' new-user.phtml
<h2> New User Registration </h2>
<p> This page will hold the content for the registration form </p>
<a href="/users"><< Back to Home</a>
您缺少这样一个模板映射。
// Generated by ZF2's ./bin/templatemap_generator.php
return [
'application/contact/index' => __DIR__ . '/view/application/contact/index.phtml',
'application/index/index' => __DIR__ . '/view/application/index/index.phtml',
'application/login/index' => __DIR__ . '/view/application/login/index.phtml',
'application/login/newpassword' => __DIR__ . '/view/application/login/newpassword.phtml',
'application/login/resetpassword' => __DIR__ . '/view/application/login/resetpassword.phtml',
'application/menu/post' => __DIR__ . '/view/application/menu/post.phtml',
'application/news/index' => __DIR__ . '/view/application/news/index.phtml',
'application/news/post' => __DIR__ . '/view/application/news/post.phtml',
'application/pagination' => __DIR__ . '/view/application/pagination.phtml',
'application/registration/index' => __DIR__ . '/view/application/registration/index.phtml',
'error/index' => __DIR__ . '/view/error/index.phtml',
'layout/layout' => __DIR__ . '/view/layout/layout.phtml',
];
您可以通过在您的module/Users
文件夹中运行php ../../vendor/bin/templatemap_generator.php
命令生成一个。之后在你的module.config.php
文件里面的view_manager
数组把这个'template_map' => include __DIR__ . '/../template_map.php',