0

This error appears during execution of the Channels Entry API in an API extension:

A PHP Error was encountered Severity: Notice Message: Undefined property: EE::$stats Filename: api/Api_channel_entries.php

The API library is loaded successfully:

 ee()->load->library('api');
 ee()->api->instantiate('channel_entries');
 ee()->api->instantiate('channel_fields');

and I am making sure the API user has permission (SuperAdmin).

The data array looks like this:

$data = array(
'title'         => $tTourTitle, 
'field_id_127'  => $tTourDuration, 
'field_id_136'  => $pCountry, 
'field_id_137'  => "$tTourCity", 
'field_id_141'  => "$tIncludes",  
'field_id_142'  => "$tExcludes", 
'field_id_143'  => "$tNotes", 
'field_id_144'  => "$tDescription", 
'field_id_145'  => "$pTour->Opt", 
'field_id_149'  => $tTourPreferred 
);

and I am executing the call according to EE 2.11.1 documentation:

ee()->api_channel_fields->setup_entry_settings($this->aEESettings['experiences_channel_id'], $data);

if($pTourId !== ''){
  $updateResult = ee()->api_channel_entries->save_entry($data, $this->aEESettings['experiences_channel_id'], $pTourId);
} else {
  $updateResult = ee()->api_channel_entries->save_entry($data, $this->aEESettings['experiences_channel_id']);
}

Why would I get this stats object error? Do I need to load any other models/apis to get this working?

Not sure if this matters, but we are using the Structure AddOn.

Thanks in advance for your input.

  • Follow-up: if I comment the line of code in question, then the code runs through successfully. All entries appear in the back-end, however, they are not rendered in the front-end - unless the entry is accessed and saved in the back-end. Are these two issues related? – EXODev Jun 22 '16 at 7:50
0

In the meantime I have figured out this problem. When using the API library, it is required to also load the stats library. Like so:

 ee()->load->library('api');
 ee()->load->library('stats');
 ee()->api->instantiate('channel_entries');
 ee()->api->instantiate('channel_fields');
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.