Skip to content

WinShop TBP,取得指標與標記所屬內容資料幫助函式。

Notifications You must be signed in to change notification settings

winhogit/gitbook_tbp_document

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

description
取得帶有標記 (tag) 的指標 (pointer) 資料,簡稱:TBP

WinShop 取得指標與標記所屬內容資料幫助函式

函式起始

使用 TBP() 開頭,後面可以使用 -> 串接附帶函式增加條件

  • 第一參數為必填,請輸入指標名稱
  • 第二參數為選填,請輸入布林代數
    • 如果為 "是",第一參數改為輸入資料 url 查詢
    • 如果為 "否" 或是不輸入,則是原本以指標進行搜尋功能

{% tabs %} {% tab title="範例 1" %} 假設有一指標 abc

TBP('abc');

{% endtab %}

{% tab title="範例 2" %} 假設有一指標以變數帶入。

TBP($pointer);

{% endtab %}

{% tab title="範例 3" %} 假設以商品首頁 url 搜尋。

TBP('products', true);

{% endtab %} {% endtabs %}


函式 find()

指定查詢條件,可以輸入一項參數,以下是可以使用的各參數及其意義:

參數意義說明範例
children搜尋指定指標子層資料
TBP($pointer)->find('children');
descendants搜尋指定指標下層資料
TBP($pointer)->find('descendants');
parent搜尋指定指標父層資料
TBP($pointer)->find('parent');
ancestors搜尋指定指標上層資料
TBP($pointer)->find('ancestors');
leaf搜尋指定指標底層資料
TBP($pointer)->find('leaf');
self搜尋指定指標資料
TBP($pointer)->find('self');

{% hint style="info" %} 如果沒有使用此函式,TBP() 一律以 children 條件查詢。 {% endhint %}


函式 tag()

指定查詢的標記,可以輸入一項參數,以下是可以使用的各參數及其意義:

參數意義說明範例
new最新
TBP($pointer)->tag('new');
hot熱門
TBP($pointer)->tag('hot');
sale促銷
TBP($pointer)->tag('sale');
custom1自訂 1
TBP($pointer)->tag('custom1');
custom2自訂 2
TBP($pointer)->tag('custom2');

{% hint style="info" %} 如果沒有使用,則不限制查詢資料。 {% endhint %}

函式可以多個串聯,範例:

TBP($pointer)->tag('new')->tag('sale')->get();

函式 sort()

指定查詢的排序,可以輸入一項參數,以下是可以使用的各參數及其意義:

參數意義說明範例
nested依照分類排序
TBP($pointer)->sort('nested');
create依照建立時間排序
TBP($pointer)->sort('create');
create_desc依照建立時間反向排序
TBP($pointer)->sort('create_desc');
public依照顯示時間排序、如果沒有顯示時間 public_at 則以建立時間排序
TBP($pointer)->sort('public');
public_desc依照顯示時間反向排序、如果沒有顯示時間 public_at 則以建立時間反向排序
TBP($pointer)->sort('public_desc');
enable依照啟用時間排序、如果沒有啟用時間 enable_at 則以建立時間排序
TBP($pointer)->sort('enable');
enable_desc依照啟用時間反向排序、如果沒有啟用時間 enable_at 則以建立時間反向排序
TBP($pointer)->sort('enable_desc');

{% hint style="info" %} 如果沒有使用,一律以 nested 條件排序。 {% endhint %}


函式 limit()

指定查詢的數量,如果有使用必填輸入一項整數參數。

範例

TBP($pointer)->limit(1); // 限制查詢一筆資料
TBP($pointer)->limit(2); // 限制查詢二筆資料
TBP($pointer)->limit(30); // 限制查詢三十筆資料

{% hint style="info" %} 如果沒有使用,沒有限制數量。 {% endhint %}

{% hint style="warning" %} 請注意!如果是查詢多個模組,每個模組會各自計算查詢數量。 {% endhint %}


函式 populate()

指定查詢資料的關聯資料,可以輸入一項陣列參數,以下是可以使用的各陣列元素及其意義:

參數意義說明範例
nested分類樹節點資料
TBP($pointer)->populate(['nested']);
images圖片資料
TBP($pointer)->populate(['images']);
attach附件資料
TBP($pointer)->populate(['attach']);
seoSEO 資料關聯
TBP($pointer)->populate(['seo']);
tag標記關聯
TBP($pointer)->populate(['tag']);
state啟用狀態關聯
TBP($pointer)->populate(['state']);
stock庫存關聯
TBP($pointer)->populate(['stock']);
ship_exclude排除的運費規格
TBP($pointer)->populate(['ship_exclude']);
ship_scale_match運費規格關聯
TBP($pointer)->populate(['ship_scale_match']);
description描述資料
TBP($pointer)->populate(['description']);
redirect重導向
TBP($pointer)->populate(['redirect']);
finance_clone關聯的投資人專區
TBP($pointer)->populate(['finance_clone']);
lockedModel鎖定模式
TBP($pointer)->populate(['lockedModel']);

{% hint style="info" %} 如果沒有使用,一律以 ['images', 'description'] 作為關聯條件。 {% endhint %}


函式 get()

結尾函式,最後串連呼叫的函式,才能取得查詢的資料。

{% hint style="info" %} 除了結尾函式與起始函式 TBP() 以外,其他函式沒有順序分別。 {% endhint %}

可以輸入一項參數,以下是可以使用的各參數及其意義:

參數意義說明範例
products僅取出商品資料
TBP($pointer)->get('products');
news僅取出最新消息資料
TBP($pointer)->get('news');
message僅取出訊息管理資料
TBP($pointer)->get('message');
aboutus僅取出關於我們資料
TBP($pointer)->get('aboutus');
download僅取出下載檔案資料
TBP($pointer)->get('download');
qa僅取出常見問題資料
TBP($pointer)->get('qa');
null取出所有模組資料
(null 不是字串,不要用單引號包裹)
TBP($pointer)->get(null);

{% hint style="info" %} 如果沒有填寫參數,預設查詢訊息管理資料:message。 {% endhint %}

{% tabs %} {% tab title="範例 1" %} 只設定指標 $pointer,其他都預設。

TBP($pointer)->get();

{% endtab %}

{% tab title="範例 2" %} 指標 abc、查詢所有最下層 (內容) 資料、以發佈日期反向排序、
帶有最新標記、僅取得最新消息資料。

TBP('abc')->find('leaf')->tag('new')->sort('public_desc')->get('news');

{% endtab %}

{% tab title="範例 3" %} 指標 $pointer、查詢所有上層資料、僅取得商品資料。

TBP($pointer)->find('ancestors')->get('products');

{% endtab %}

{% tab title="範例 4" %} 以某商品資料 url、查詢所有上層資料。

TBP('water', true)->find('ancestors')->get();

{% endtab %}

{% tab title="範例 5" %} 跨模組查詢同指標資料。

TBP($pointer)->find('leaf')->get(null);

{% endtab %} {% endtabs %}


函式 paginate()

分頁結尾函式,最後串連呼叫的函式,才能取得查詢的資料。

{% hint style="info" %} 除了結尾函式與起始函式 TBP() 以外,其他函式沒有順序分別。 {% endhint %}

此函式有三個參數:

  • 第一項參數與函式 get() 相同。
  • 第二項參數為正整數,代表每頁資料筆數。
  • 第三項參數為正整數,代表分頁號碼
    • 如果沒有指定會自動抓取網頁 page 網址參數。
    • 完全沒有參數預設是第 1 頁。

{% tabs %} {% tab title="範例 1" %} 只設定指標 $pointer,其他都預設。

TBP($pointer)->paginate();

{% endtab %}

{% tab title="範例 2" %} 指標 abc、查詢所有最下層 (內容) 資料、以發佈日期反向排序、
帶有最新標記、僅取得最新消息資料。

TBP('abc')->find('leaf')->tag('new')->sort('public_desc')->paginate('news');

{% endtab %}

{% tab title="範例 3" %} 雷同範例 2,增加限制輸出 20 筆資料限制。

TBP('abc')->find('leaf')->tag('new')->sort('public_desc')->paginate('news', 20);

{% endtab %}

{% tab title="範例 4" %} 雷同範例 3 增加輸出第 2 頁資料。

TBP('abc')->find('leaf')->tag('new')->sort('public_desc')->paginate('news', 20, 2);

{% endtab %} {% endtabs %}


函式 testMode()

結尾函式,測試模式輸出,使用方式同函式 get()

{% hint style="info" %} 除了結尾函式與起始函式 TBP() 以外,其他函式沒有順序分別。 {% endhint %}

輸出查詢資料用的 SQL 語句集合而不是資料。

範例

只設定指標 $pointer,其他都預設,輸出 SQL 語法集合。

TBP($pointer)->testMode();

About

WinShop TBP,取得指標與標記所屬內容資料幫助函式。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors