2015-10-14 56 views
1

我創建了一個包含3個視圖(索引,登錄,註冊)的簡單用戶模塊。 我想將它們映射到具有以下代碼的用戶模塊中的IndexController。 代碼運行沒有任何錯誤,但不顯示模板無法在Zend Framework中映射不同的動作和控制器2

控制器代碼:用戶的\ src \用戶\控制器\的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; 
    } 
} 

並考慮到模板

用戶\視圖\索引\ index.phtml

<h1>Welcome to Users Module</h1> 
    <a href="https://stackoverflow.com/users/index/login">Login</a> 
    <br> <br> 
    <a href="https://stackoverflow.com/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> 

用戶\圖\首頁\新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> 

回答

1

你缺少一個模板圖,如這一點。

// 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',

相關問題