99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

CakePHP的擴展視圖

2018-01-14 12:23 更新

很多時候,當制作網(wǎng)頁時,我們想在網(wǎng)頁頁面重復另一網(wǎng)頁的某些部分。 CakePHP能實現(xiàn)從一個視圖繼承一個視圖,因此,我們不必再重復寫代碼。extend()方法用于在視圖文件中繼承視圖。這個方法需要一個參數(shù),帶文件路徑的視圖文件名,但不必帶擴展名.ctp。

在以下項目中,修改如下所示config/routes.php文件。

config/routes.php

<?php
   use CakeCorePlugin;
   use CakeRoutingRouteBuilder;
   use CakeRoutingRouter;

   Router::defaultRouteClass('DashedRoute');
   Router::scope('/', function (RouteBuilder $routes) {
      $routes->connect('extend',['controller'=>'Extends','action'=>'index']);
      $routes->fallbacks('DashedRoute');
   });
   Plugin::routes();

src/Controller/下創(chuàng)建ExtendsController.php文件。復制以下代碼至其中。

src/Controller/ExtendsController.php

<?php
   namespace AppController;
   use AppControllerAppController;

   class ExtendsController extends AppController{
      public function index(){
      }
   }
?>

src/Template目錄下創(chuàng)建一個名為Extends的文件夾,并在Extends文件夾下創(chuàng)建一個名為header.ctp視圖文件。復制以下代碼至其中。

src/Template/Extends/header.ctp

<div align = "center"><h1>Common Header</h1></div>

<?= $this->fetch('content') ?>

Extends目錄下創(chuàng)建另一個視圖文件index.ctp。復制以下代碼至其中。在這里,我們繼承了header.ctp。

src/Template/Extends/index.ctp

<?php $this->extend('header'); ?>
This is an example of extending view.

通過訪問以下網(wǎng)址執(zhí)行上面的例子。

http://localhost:85/CakePHP/extend

輸出

執(zhí)行以上程序,您會看到以下頁面。



以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號