Answer the question
In order to leave comments, you need to log in
How to fix this error when working with yii2-curl - "Call to a member function setOption() on string"?
Good day!
At the moment I'm testing a service for adding filters of the current data attribute to the database. But it first checks for the presence of the attribute in the filter database. If it is not present, then it adds the attribute to the DBMS, and removing it from the database of empty attributes in Redis. Next, it performs operations to add the requested filter.
The initial actions of the service look like this (they are performed thanks to the yii2-curl library :
$attributeId = strtolower($pm['attribute']);
$isDataState = (new curl\Curl)->post(((!empty($_SERVER['HTTPS'])) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] .'/admin/api/dataServices/filters/notEmptyAttribute/show');
$attributeGenerator = (new curl\Curl)->post(((!empty($_SERVER['HTTPS'])) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] .'/admin/api/dataServices/filters/Attribute/send');
$microQuery = [
'generatorQuery' => [
'parameters' => [
'attribute' => $attributeId,
'group' => 'data'
]
],
'validQuery' => [
'parameters' => [ 'attribute' => $attributeId ]
]
];
$idsSend = $isDataState->setOption(CURLOPT_POSTFIELDS, http_build_query(['svcQuery' => JSON::encode($microQuery['validQuery'])]));
$resValid = JSON::decode($idsSend);
if($resValid['avabillityData'] == 1){ $agSend = $attributeGenerator->setOption(CURLOPT_POSTFIELDS, http_build_query(['svcQuery' => JSON::encode($microQuery['generatorQuery'])])); }
if((!$idsSend && !$agSend) || !$idsSend || !$agSend){
\Yii::$app->response->statusCode = 502;
$serviceResponse[] = 'Operation service error!';
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question