黄色电影一区二区,韩国少妇自慰A片免费看,精品人妻少妇一级毛片免费蜜桃AV按摩师 ,超碰 香蕉

CakePHP 擴展視圖

cakephp 擴展視圖

 

很多時候,在制作網(wǎng)頁時,我們希望在其他頁面中重復頁面的某些部分。 cakephp 具有這樣一種功能,可以通過它在另一個視圖中擴展視圖,為此,我們無需再次重復代碼。

extend() 方法用于擴展 view 文件中的視圖。該方法接受一個參數(shù),即帶有路徑的視圖文件的名稱。在提供視圖文件的名稱時不要使用擴展名 .ctp。

 

示例

在 config/routes.php 文件中進行更改,如以下程序所示。

 

config/routes.php

use cake\http\middleware\csrfprotectionmiddleware;
use cake\routing\route\dashedroute;
use cake\routing\routebuilder;
$routes--->setrouteclass(dashedroute::class);
$routes->scope('/', function (routebuilder $builder) {
   $builder->registermiddleware('csrf', new csrfprotectionmiddleware([
      'httponly' => true,
   ]));
   $builder->applymiddleware('csrf');
   $builder->connect('extend',['controller'=>'extends','action'=>'index']);
   $builder->fallbacks();
});

src/controller/extendscontroller.php 中創(chuàng)建一個 extendscontroller.php 文件。 將以下代碼復制到控制器文件中。

 

src/controller/extendscontroller.php

   namespace app\controller;
   use app\controller\appcontroller;
   class extendscontroller extends appcontroller{
      public function index(){
      }
   }

src/template 和該目錄下創(chuàng)建一個目錄 extendsder 創(chuàng)建一個名為 header.php 的 view 文件。將以下代碼復制到該文件中。

 

src/template/extends/header.php

common header

fetch('content') ?>

extends 目錄下創(chuàng)建另一個 view,名為 index.php。 在該文件中復制以下代碼。在這里,我們擴展了上面的視圖 header.php.

 

src/template/extends/index.php

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

通過訪問以下 url http://localhost/cakephp4/extend 來執(zhí)行上面的例子

 

輸出

執(zhí)行后,您將收到以下輸出。

下一節(jié):cakephp 查看元素

cakephp 教程

相關(guān)文章