我正在構建一個Zend Framework MVC應用程序,並且難以配置我的Zend_Layout。Zend_Layout配置:何時以及如何?
首先,我的應用程序資源都在被裝載在引導用下面的代碼資源插件:
protected function _initResourcePlugins() {
$this->registerPluginResource('Log');
$this->registerPluginResource('Router');
$this->registerPluginResource('Db');
$this->registerPluginResource('View');
}
,因爲我在處理登錄/登出我尚未創建我的佈局資源插件前端控制器插件和我的佈局配置取決於用戶是否登錄(以及其他上下文相關信息)。我在生活踢佈局,在我的application.ini下面幾行:
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/professional"
resources.layout.layout = "ver1"
然後我用一個前端控制器插件進行配置。這裏的插件:
public function postDispatch(\Zend_Controller_Request_Abstract $request) {
$layout = Zend_Layout::getMvcInstance();
$path = $layout->getLayoutPath();
// include static content
$layout->header = include($path . '/includes/header.phtml');
$layout->footer = include($path . '/includes/footer.phtml');
if(APPLICATION_ENV == 'development') {
$layout->dev = include($path . '/includes/dev.phtml');
}
if(RW_Helper::isLoggedIn()) {
$layout->sidebar = include($path . '/includes/sbar_secure.phtml');
} else {
$layout->sidebar = include($path . '/includes/sbar_public_login.phtml');
}
}
(我知道它不是特別漂亮,但我會在稍後處理)。
現在,問題是我唯一可以運行的事件是postDispatch事件。如果我嘗試在運行它,比方說,dispatchLoopStartup,我得到一個錯誤,如:
「警告UiWidgetElement裝飾不能沒有...註冊的視圖對象渲染」我不知道該視圖對象它在尋找。 (佈局和應用程序視圖中是否有單獨的視圖?)我不確定我應該在哪裏/如何注入它或提供它。如果它追逐我設置爲資源的觀點,我會認爲它可以通過查閱引導程序輕鬆找到它...
我不想讓版面附加到postDispatch事件,因爲a)它感覺語義上不正確,b)我冒險多次執行它(如果我在請求中執行多個動作)。
我錯過了什麼?
謝謝!
看看http://stackoverflow.com/a/14397528/949273 – tasmaniski