S
S
Sergey Zolotarev2022-01-26 10:14:04
Yii
Sergey Zolotarev, 2022-01-26 10:14:04

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!';
          }

And when testing it on the client side, XDebug returned an error: "Call to a member function setOption() on string" , referring to the 18th line of the code example above. How to call a function method so that it does not return a result in a string type? Thank you in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question