Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
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. – Alice Heaton Apr 12 at 13:30

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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