在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");
}
}
这真的很容易。我将根据您想要检索的内容和手头的信息向您展示不同的方法。当然我知道你所知道的是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/>";
}
如果这回答了你的问题,请告诉我。
有关如何使用laravel编写查询的更多信息WHMCS当前用于与数据库交互,您可以访问https://laravel.com/docs/5.2/queries