2013-02-28 111 views
0

我想讓自動匹配視圖文件 - 控制器動作。Zend Framework 2視圖管理器 - 查看文件和請求的動作匹配

如果/Web/TestController/testAction(模塊/控制器/動作)的要求,

ZF2嘗試加載這樣的觀點:/web/test/test

然後,我要加入這一行template_map,使其工作:

'web/test/test'  => __DIR__ . '/../view/pages/test/test.phtml', 

但我不想爲所有操作添加此行。

它可以工作是這樣的:

'web/{ABC}/{XYZ}'  => __DIR__ . '/../view/pages/{ABC}/{XYZ}.phtml', 

我如何讓這個它會自動匹配?

module.config.php:

return array(
    'router' => array(
     'routes' => array(
      'web' => array(
       'type' => 'segment', 
       'options' => array(
        'route' => '[/:action]', 
        'constraints' => array(), 
        'defaults' => array(
         'controller' => 'Web\Controller\Test', 
        ), 
       ) 
      ) 
     ) 
    ), 


    '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(

      'layout/test'  => __DIR__ . '/../view/layouts/test/test.phtml', 
      'layout/default' => __DIR__ . '/../view/layouts/default/default.phtml', 
      'error/404'   => __DIR__ . '/../view/error/404.phtml', 
      'error/index'  => __DIR__ . '/../view/error/index.phtml', 

      'web/test/test'  => __DIR__ . '/../view/pages/test/test.phtml', 
     ), 

     'template_path_stack' => array(
      __DIR__ . '/../view', 
     ), 

     'layout'     => 'layout/default' 
    ), 
); 
+0

@KivankErten這就是'template_path_stack'的用途...... – Ocramius 2013-02-28 14:19:26

+0

@Ocramius謝謝;)這是一個文件夾名稱問題。 – 2013-02-28 15:18:51

回答

0

你應該重新命名 「」 目錄 「網絡」 並更改配置文件如下

'web/test/test'  => __DIR__ . '/../view/web/test/test.phtml',