当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。