Comment to 'Help with creating public API'
  • UNA Version: 14.0.0-A3

    When using the curl example on the DEV API page:

    An error occurs:

    PHP Fatal error: Uncaught Error: Cannot use object of type stdClass as array in /home/ext/sites/una/modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php:196
    Stack trace:
    #0 /home/ext/sites/una/modules/base/general/classes/BxBaseModGeneralModule.php(1230): BxBaseModGeneralFormsEntryHelper->addData()
    #1 /home/ext/sites/una/inc/classes/BxDolRequest.php(132): BxBaseModGeneralModule->serviceEntityAdd()
    #2 /home/ext/sites/una/inc/classes/BxDolRequest.php(57): BxDolRequest::_perform()
    #3 /home/ext/sites/una/inc/classes/BxDolService.php(51): BxDolRequest::processAsService()
    #4 /home/ext/sites/una/api.php(72): BxDolService::call()
    #5 {main}
      thrown in /home/ext/sites/una/modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php on line 196
    

    Temporary Fix:

    To resolve this issue, check for the type of the $aValues variable passed to the addData method. If it is not an array, cast it to an array.

    In /home/ext/sites/una/modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php, modify the addData method as follows:

    public function addData($iProfile, $aValues, $sDisplay = false)
    {
        if (!is_array($aValues)) {
            $aValues = (array) $aValues;
        }
        // Rest of the method implementation
    }
    

    This modification ensures that $aValues is always treated as an array, preventing the fatal error and allowing the method to process the data correctly.