ThinkPHP5 開閉原則 多版本支援

2021-09-29 02:49:55 字數 522 閱讀 9946

一般  在控制器多傳入乙個引數  $version

public function getbanner($id)

return $banner ;}}

public function getbanner($id,$version){}

然後判斷 $version

if($version == 1) {}

if($version == 2){}

...設計**的原則 開閉原則 擴充套件開放 修改閉合 適應**的改變 變更

以擴充套件的形式 修改**

如 版本迭代 在原有的**上增加判斷 極易影響原來的功能

需要 同時支援新老版本 使用者自定義公升級

路由 傳入v1訪問v1版本的 傳入v2訪問v2版本的

route::get('api/:version/banner/:id','api/:version.banner/getbanner') ;

此時 訪問url時 區分大小寫 (v) 要與v1 v2目錄名相等 注意大小寫

thinkphp5多對多關聯,中間表進行多型關聯

這是中間表,不要問我為什麼這麼設計,這是領導要求的 create table at relation table id int 11 not null auto increment,aid int 11 not null comment aid bid int 11 not null comment...

ThinkPHP5使用快取

cache 使用復合快取型別 type complex 預設使用的快取 default 驅動方式 type file 在這設定換人的快取方式 快取儲存目錄 path cache path,檔案快取 file 驅動方式 type file 設定不同的快取儲存目錄 path runtime path f...

thinkphp5內建標籤

知道內建標籤怎麼用,查手冊的時候好查 卻功能的時候在裡面找著來用 1 內建標籤23 變數輸出使用普通標籤就足夠了,但是要完成其他的控制 迴圈和判斷功能,就需要借助模板引擎的標籤庫 4功能了,系統內建標籤庫的所有標籤無需引入標籤庫即可直接使用。5內建標籤包括 6標籤名作用包含屬性 7include 包...