為了讓不同的View以相同的布局進行顯示,我們可以編寫布局模板檔案,並以layout.phtml為名稱進行儲存,並在Index.php中指定這個檔案所在的位置。
- require_once 'Zend/Layout.php';
- Zend_Layout::startMvc(array('layoutPath'=>'../application/default/layouts'));
在布局檔案中,我們可以指定網頁需要使用的樣式檔案,JavaScript指令檔。
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <?php
- $request = Zend_Controller_Front::getInstance()->getRequest();
- $this->headTitle('視圖中使用視圖')
- ->headTitle($request->getModuleName())
- ->headTitle($request->getActionName())
- ->headTitle($request->getControllerName())
- ->setSeparator('|');
-
- echo $this->headTitle();
- $this->headLink()->appendStylesheet($this->baseUrl . "/css/style.css")
- ->appendStylesheet($this->baseUrl . "/css/demo.css");
- echo $this->headLink();
- $this->headScript()->appendFile($this->baseUrl . "/js/jquery-1.2.6.js")
- ->appendFile($this->baseUrl . "/js/jquery.datePicker.js")
- ->appendFile($this->baseUrl . "/js/demo.js");
- echo $this->headScript();
- ?>
- </head>
- <body>
- <div id='bodywrapper'>
- <div id='header'>
- <?php echo $this->partial('header.phtml', 'default'); ?>
- </div>
- <div id='sidebar' >
- <?php echo $this->partial('leftside.phtml', 'default'); ?>
- </div>
- <div id='midcontent' >
- <?php echo $this->layout()->content; ?>
- </div>
- <div id='footer' >
- <?php echo $this->partial('footer.phtml', 'default'); ?>
- </div>
- </div>
- </body>
- </html>