3

Whenever I try to use $_SESSION or variable_set it breaks the Entity API. It says

"Fatal error: Call to undefined function entity_get_info() in mydrupal\sites\all\modules\entity\includes\entity.inc on line 55"

And then I have to reinstall the entire website because this fatal error shows up on every page. So I can't even access any of the adminscreens or anything to uninstall the modules or anything.

Does anybody here know if this is just a bug or am I doing something wrong? I was just filling the session with an entity.

1
  • Drupal keeps it's own cache of entities. If you keep it in a session, on the next page load there will be a discrepency between what Drupal thinks the state of the object is and what you think it is. Best to avoid this, keep the ID instead. Apr 12 '13 at 13:30
2

Variables are serialised (as are session writes as I understand it), and complex objects like entity API entities don't serialise well.

The better solution would be to store the entity type and ID in the session, then load it when reading:

$_SESSION['saved_entity'] = array('type' => 'node', 'id' => 1);

...

$saved_entity = entity_load($_SESSION['saved_entity']['type'], array($_SESSION['saved_entity']['id']));

And do the same thing for the variables.

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.