■フロントコントローラ
大枠(レイアウト部分)が置いてあるディレクトリのパスはここで指定してもよいと思う。
/public_html/index.php
Zend_Layout::startMvc(array( 'layout' => 'layout',// layout.phtml 'layoutPath' => '../application/modules/admin/views/layouts/'// path )); $front = Zend_Controller_Front::getInstance();
■コントローラ
まぁ大体一つのコントローラ内でレイアウトが変わるなんて事はないから、initで設定してイイよね。
/** * init * @return void */ public function init() { $this->_helper->layout->setLayout('layout');// layout.phtml //$this->_helper->layout->setLayoutPath('../application');// path $this->_helper->layout->assign('menu', $this->view->render('menu.phtml')); }
こんな感じにしておけば、以下の様な感じでイケる!
■ビュー
/application/modules/admin/views/scripts/index/index.phtmlの部分は$this->layout()->contentに出力される。
/application/modules/admin/views/layouts/layout.phtml
<div id="sidebar"> <?php echo $this->layout()->menu ?> </div> <div id="main"> <?php echo $this->layout()->content ?> </div>
■その他の設定
/** * init * @return void */ public function init() { $this->_helper->layout->setLayout('layout');// layout.phtml $this->_helper->layout->assign('menu', $this->view->render('menu.phtml')); $this->_helper->layout->disableLayout();// レイアウトを無効化できる $this->_helper->layout->setContentKey('main');// デフォルト名$this->layout()->contentを$this->layout()->mainに変更できる }