Zend Framework之Layout

來源:互聯網
上載者:User

 為了讓不同的View以相同的布局進行顯示,我們可以編寫布局模板檔案,並以layout.phtml為名稱進行儲存,並在Index.php中指定這個檔案所在的位置。

  1. require_once 'Zend/Layout.php';
  2. Zend_Layout::startMvc(array('layoutPath'=>'../application/default/layouts'));

在布局檔案中,我們可以指定網頁需要使用的樣式檔案,JavaScript指令檔。

  1. <html>
  2. <head>
  3.    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4.    <?php 
  5.       $request = Zend_Controller_Front::getInstance()->getRequest();
  6.       $this->headTitle('視圖中使用視圖')
  7.            ->headTitle($request->getModuleName())
  8.            ->headTitle($request->getActionName())
  9.            ->headTitle($request->getControllerName())
  10.            ->setSeparator('|');
  11.   
  12.       echo $this->headTitle();
  13.       $this->headLink()->appendStylesheet($this->baseUrl . "/css/style.css")
  14.                        ->appendStylesheet($this->baseUrl . "/css/demo.css");
  15.       echo $this->headLink();
  16.       $this->headScript()->appendFile($this->baseUrl . "/js/jquery-1.2.6.js")
  17.                          ->appendFile($this->baseUrl . "/js/jquery.datePicker.js")
  18.                          ->appendFile($this->baseUrl . "/js/demo.js");
  19.       echo $this->headScript();
  20.     ?>
  21. </head>
  22. <body>
  23.    <div id='bodywrapper'>
  24.      <div id='header'>
  25.        <?php echo $this->partial('header.phtml', 'default'); ?>
  26.      </div>
  27.      <div id='sidebar' >
  28.        <?php echo $this->partial('leftside.phtml', 'default'); ?>
  29.      </div>
  30.      <div id='midcontent' >
  31.        <?php echo $this->layout()->content; ?>
  32.      </div>
  33.      <div id='footer' >
  34.        <?php echo $this->partial('footer.phtml', 'default'); ?>
  35.      </div>
  36.     </div>
  37. </body>
  38. </html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.