當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP WHMCS IntelligentSearch用法及代碼示例

在智能搜索完成時執行

參數

變量 類型 注意
searchTerm string 正在搜索的詞
numResults int 要返回的結果數

響應

一組額外的搜索結果。請參閱數組結構的示例。 WHMCS 7.7 之前的版本支持字符串響應。

示例代碼

<?php

add_hook('IntelligentSearch', 1, function ($vars) {
    /**
     * This is an example of array return for an Intelligent Search.
     * This format is supported in the blend WHMCS Admin Template.
     * Any template based on blend and updated to WHMCS 7.7+ is also supported.
     */
    $searchResults = array();

    // look for exact matches in client notes field
    $result = \WHMCS\Database\Capsule::table('tblclients')
        ->where('notes', $vars['searchTerm'])
        ->get();

    foreach ($result as $client) {
        $searchResults[] = [
            'title' => $client->firstname . ' ' . $client->lastname, // The title of the search result. This is required.
            'href' => 'clientssummary.php?userid=' . $client->id, // The destination url of the search result. This is required.
            'subTitle' => $client->email, // An optional subtitle for the search result.
            'icon' => 'fal fa-user', // A font-awesome icon for the search result. Defaults to 'fal fa-star' if not defined.
        ];
    }
    return $searchResults;
});

相關用法


注:本文由純淨天空篩選整理自whmcs.com大神的英文原創作品 IntelligentSearch。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。