2015-12-02 66 views
0

如何在Zend2中的一個模塊中使用不同的佈局 我在我的代碼中編寫並且沒有效果 我需要使用不同佈局來執行一個不同的操作控制器如何在Zend2中的一個模塊中使用不同的佈局

class IndexController extends AbstractActionController 
 
{ 
 
    public function indexAction() 
 
    { \t $this->layout('layout/layout'); 
 
\t \t $view = new ViewModel(); 
 
\t \t $menu = new ViewModel(); 
 
\t \t $menu->setTemplate('application/menu'); 
 
     $view->addChild($menu, 'menu'); 
 
    return $view; 
 
    } 
 
\t 
 
\t public function portfolioAction() 
 
    { 
 
\t \t $this->layout('layout/portfolio'); 
 
\t \t $view = new ViewModel(); 
 
\t \t $menu = new ViewModel(); 
 
\t \t $menu->setTemplate('application/menu'); 
 
     $view->addChild($menu, 'menu'); 
 
    return $view; 
 
    } 
 
}

,這是我viewManager

'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(
 
\t \t 'layout/portfolio'   => __DIR__ . '/../view/layout/layout_portfolio.phtml', 
 
      'layout/layout'   => __DIR__ . '/../view/layout/layout.phtml', 
 
      'application/index/index' => __DIR__ . '/../view/application/index/index.phtml', 
 
      'error/404'    => __DIR__ . '/../view/error/404.phtml', 
 
      'error/index'    => __DIR__ . '/../view/error/index.phtml', 
 
     ), 
 
     'template_path_stack' => array(
 
      __DIR__ . '/../view', 
 
     ), 
 
    ),

回答

0

我認爲佈局是由事件MvcEvent :: EVENT_DISPATCH設置的。 所以我寫了一個監聽器來改變佈局。您可以在https://github.com/dafap/DafapLayout看到我的解決方案,並根據您的需求進行調整。

相關問題