2011-01-19 18 views
2

我知道&使用了非常基本的Zend Framework的佈局,其中我在整個站點中使用了1個佈局。但現在我需要更多的中級/有組織的設置。如何在Zend Framework中設置多個佈局。例如。公開/登錄/模塊的各種組合

  • 公共站點佈局將具有div#mainContent佔用整個12列(使用960gs)
  • 登錄的站點將具有div#mainContent佔用9列+側杆與3列
  • 在邊欄中的現場記錄,各種可能包含不同的模塊(不Zend框架的模塊,更像是「盒/小部件」)
  • 他們將有不同的導航菜單過於

我正在考慮使用1個基本佈局,其中2個子佈局將「擴展」。基本佈局將只包含<html>聲明headScripts等到<body>,那麼子佈局將包含包裝的定義divsdiv.grid_12, grid_9, grid_3。我怎樣才能實現這個「推」,基本上,我只是想重用代碼

而且什麼好辦法使側邊欄盒/部件

回答

9

我根據我的網站的子域佈局之間的切換。

下面是我使用的佈局插件...

class App_Layout_Controller_Plugin_Layout extends Zend_Layout_Controller_Plugin_Layout 
{ 

    public function preDispatch(Zend_Controller_Request_Abstract $request) 
    { 
     $layout = $this->getLayout(); 
     $filename = $layout->getLayoutPath() . '/' . $request->getModuleName() . '.' . $layout->getViewSuffix(); 

     //check if the layout template exists, if not use the default layout set in application.ini 
     if (file_exists($filename)) 
     { 
      $this->getLayout()->setLayout($request->getModuleName()); 
     } 
    } 

} 

當然你也可以修改這個根據自己的需要。

確保你設置你的application.ini正確太像包括以下元素...

resources.layout.layout = "default" 
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts" 
resources.layout.pluginClass = "App_Layout_Controller_Plugin_Layout" 

在我的情況,我有:

default.phtml,admin.phtml, clients.phtml

我希望這有助於...
天使

2

我們這樣做的方式,我不知道它是否是最好的方法,是在每個控制器中的init()方法中設置當前佈局。

因此,例如,如果我們有這個網址:www.mysite.com/social/

class SocialController extends BaseController 
{ 
    public function init(){ 
     $layout = $this->_helper->layout(); 
     $layout->setLayout('social'); 
    } 
} 

然後config.ini文件中:

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/" 

而且還有一個socia.phtml定義在resources.layout.layoutPath中

相關問題