2010-11-23 20 views

回答

0

默認情況下,這是不可能的,因爲引導是(顯然) 。引導程序無法知道,如果前端或後端被調用。您可以創建一個FrontControlle -Plugin,它讀取(自定義)配置設置和路由請求,然後設置正確的佈局。

0

我有完全相同的問題,並通過繼承bootstrap來解決它。所以,我有三個引導文件

  1. 用戶空間的一個
  2. 聯繫一個
  3. 常見的一種

類似的東西在引導文件(它們都可以放置在默認Zend的位置)

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap 
{ 

    protected function _initXXX() { 
     /* COMMON FOR ALL */ 
    } 

    /* ... etc ... */ 
} 


class BootstrapAdmin extends Bootstrap 
{ 
    protected function _initAdmin1() { 
     /* specific for admin */ 
    } 
    /* ... etc ... */ 
} 

class BootstrapUser extends Bootstrap 
{ 
    protected function _initUser1() { 
     /* specific for admin */ 
    } 
    /* ... etc ... */ 
} 

其中(1)和(2)擴展(3)。如果你願意,我重新創建代碼。

後,在index.php文件:

if ($adminMode) { 
$application->setBootstrap(APPLICATION_PATH . '/Name_of_Bootstrap_file.php', 'BootstrapAdmin'); 
} else { 
$application->setBootstrap(APPLICATION_PATH . '/Name_of_Bootstrap_file.php', 'BootstrapUser'); 
} 

我第一次做到了,我放在同一個文件中的所有類Name_of_Bootstrap_file.php,以改變他們在一起,可能會採取不同的方式下次雖然...

希望我幫助。

+0

請讓我知道結構 – aah 2010-11-23 13:52:23

0

佈局取決於哪些模塊被加載

在我CONFIGS /的application.ini

resources.layout.layout = "default" 
resources.layout.pluginClass = "Core_Controller_Plugin_ModuleBasedLayout" 

然後我的插件

<?php 
class Core_Controller_Plugin_ModuleBasedLayout 
    extends Zend_Layout_Controller_Plugin_Layout 
{ 
    public function preDispatch(Zend_Controller_Request_Abstract $request) 
    { 
     $this->getLayout()->setLayoutPath( 
      Zend_Registry::get('config')->resources->frontController->moduleDirectory 
      . DIRECTORY_SEPARATOR . $request->getModuleName() . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'layouts'); 
    } 
} 

,並在我的bootstrap.php

protected function _initConfig() { 
    Zend_Registry::set ('config', new Zend_Config ($this->getOptions())); 
} 

我的佈局存儲在視圖/佈局/ default.php

0

想到我會用我的解決方案。這假定「管理員」部分是一個模塊。

我已經開發了一個動作助手比可以根據模塊的名稱和配置交換機佈局 - ModuleLayoutLoader

您可以從您的配置文件使用關聯ModuleLayout應用程序資源插件配置。例如

resources.moduleLayout.admin.layout = "admin" 
resources.moduleLayout.anotherModule.layout = "foo" 

您還可以設置layoutPath屬性使用這樣的事情你的模塊的佈局,如果你想保持你的佈局腳本中分離

resources.moduleLayout.admin.layoutPath = APPLICATION_PATH "/path/to/admin/layout" 
相關問題