【问题标题】:Whmcs Client Custom Field ValueWmcs 客户端自定义字段值
【发布时间】:2019-03-09 22:29:17
【问题描述】:

在 WHMCS 论坛 1 周没有成功帮助后,在这里试试我的运气,并且仅支持参考文档和论坛。

我希望从客户自定义字段的字段中获取值,我知道字段名称

根据文档和论坛帖子,这在理论上应该有效,但它没有,没有返回任何内容。有什么想法吗?

    $clientFields =  Client::find($clientID)->customFieldValues  ;  
foreach($clientFields AS $field)
{

if (isset($field->customField->fieldName) 

and $field->customField->fieldName == 'NoridCID') 

{ 
    $xml .= $field->customField->value; // Add ID to XML 
}   

    else
    {
        return array("error" => "Some Error Message");

    }
}

【问题讨论】:

    标签: php xml api whmcs


    【解决方案1】:

    这应该真的很容易。我将根据你想要检索的内容和手头的信息向你展示不同的方法。当然,我知道您所知道的是fieldname,但我建议您进入您的WHMCS 安装的tblcustomfields 表并检索该自定义字段的id 值。现在让我们开始看代码:

    首先:包含以下代码:

    require("init.php");
    use WHMCS\Database\Capsule;
    

    第二:声明已知变量:

    我假设您已经拥有您所知道的价值观。所以我将在这里使用我的伪值:

    $clientID = 12;
    $customFieldID = 1;
    $customFieldName = 'Where did you hear about us?';
    

    第三:添加检索数据的代码

    我将使用四个代码。选择最适合您需要的套件。

    答:获取 1 个客户的自定义字段值。您有客户 ID 和自定义字段名称

    $customFieldValue1 =  Capsule::table('tblcustomfields')
                                    ->join('tblcustomfieldsvalues','tblcustomfieldsvalues.fieldid','=','tblcustomfields.id')
                                    ->where('tblcustomfieldsvalues.relid','=',$clientID)
                                    ->where('tblcustomfields.fieldname','=',$customFieldName)
                                    ->value('tblcustomfieldsvalues.value');
    
                                    //Use the retrieved vaue e.g echo
                                    echo $customFieldValue1."<br/>";
    

    B:获取 1 个客户的自定义字段值。您有客户 ID 和自定义字段 ID

    $customFieldValue2 = Capsule::table('tblcustomfieldsvalues')
                                    ->where('relid',$clientID)
                                    ->where('fieldid',$customFieldID)
                                    ->value('value');
    
                                    //Use the retrieved vaue e.g echo
                                    echo $customFieldValue2."<br/>";
    

    C:获取所有客户端的自定义字段值。您有客户 ID 和自定义字段名称

    $customFieldValues1 =  Capsule::table('tblcustomfields')
                                    ->join('tblcustomfieldsvalues','tblcustomfieldsvalues.fieldid','=','tblcustomfields.id')
                                    ->select('tblcustomfieldsvalues.value as value','tblcustomfieldsvalues.relid as client')
                                    ->where('tblcustomfields.fieldname','=',$customFieldName)
                                    ->get();
    
                                    //use retrieved values
                                    foreach($customFieldValues1 as $customField){
                                        $clientId = $customField->client;
                                        $customFieldValue = $customField->value;
    
                                        echo $clientId." : ".$customFieldValue."<br/>";
                                    }
    

    C:获取所有客户端的自定义字段值。您有客户 ID 和自定义字段 ID

    $customFieldValues2 =  Capsule::table('tblcustomfieldsvalues')
                                    ->select('relid as client','value')
                                    ->where('fieldid',$customFieldID)
                                    ->get();
    
                                    //use retrieved values
                                    foreach($customFieldValues2 as $customField){
                                        $clientId = $customField->client;
                                        $customFieldValue = $customField->value;
    
                                        echo $clientId." : ".$customFieldValue."<br/>";
                                    }
    

    如果这回答了您的问题,请告诉我。

    有关如何使用 WHMCS 目前用于与数据库交互的 laravel 编写查询的更多信息,您可以访问https://laravel.com/docs/5.2/queries

    【讨论】:

    • 在 WHMCS 社区论坛whmcs.community/topic/… 上还发布了另一种非常好的方法,我相信它可能有用。
    • 我正在创建一个钩子,如何获取 tblcustomfieldsvalues.relid?
    猜你喜欢
    • 2018-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多