I use Doctrine2 in my ZendFramework project and I've got a not easy to resolve for me a problem...
So, when user has successfully log in to the page, I put his object into the session:
Zend_Auth::getInstance()->getStorage()->write($user);
Everything works fine, but when I refresh the page and load an user from session:
$user = Zend_Auth::getInstance()->getStorage()->read();
And with this $user I can't do any Doctrine2 operations :-/. I'm able to use for example "getId()" method, but when I try for example use $user in any relations:
$session = new App_Model_LogSessions();
$session->setUser($user);
...
I see the Doctrine2 exception:
Entity App_Model_Users is not managed. An entity is managed if its fetched from the database or registered as new through EntityManager#persist
How can I fix this? Is there any method to "reload" the entity? I need to use the session, I don't want to load user from database in every page request. I'd like to load him once and put him to the session.
Thanks!