Currently I am finishing my degree in Computer Science and i am studying English.
I have a problem to get my entity named Waiter from session object in Symfony3.
$em = $this->getDoctrine()->getManager();
$session = $this->get('Session');
$waiter = $em->merge($session->get('waiter'));
return $this->render('default/waitermngr.html.twig',array('admin'=>$waiter));
This code returns error EntityManager#merge() expects parameter 1 to be an entity object, NULL given.
However $session object is not null because return new Response ((string)print_r($session));
returns:
Symfony\Component\HttpFoundation\Session\Session Object ( [storage:protected] => Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage Object ( [bags:protected] => Array ( [attributes] => Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag Object ( [name:Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag:private] => attributes [storageKey:Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag:private] => _sf2_attributes [attributes:protected] => Array ( [admin] => AppBundle\Entity\Waiter Object ( [idwaiter:protected] => 21 [loginwaiter:protected] => Admin [passwdwaiter:protected] => 81dc9bdb52d04dc20036dbd8313ed055 ) ) ) [flashes] => Symfony\Component\HttpFoundation\Session\Flash\FlashBag Object ( [name:Symfony\Component\HttpFoundation\Session\Flash\FlashBag:private] => flashes [flashes:Symfony\Component\HttpFoundation\Session\Flash\FlashBag:private] => Array ( ) [storageKey:Symfony\Component\HttpFoundation\Session\Flash\FlashBag:private] => _sf2_flashes ) ) [started:protected] => 1 [closed:protected] => [saveHandler:protected] => Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy Object ( [handler:protected] => Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler Object ( ) [wrapper:protected] => 1 [saveHandlerName:protected] => files ) [metadataBag:protected] => Symfony\Component\HttpFoundation\Session\Storage\MetadataBag Object ( [name:Symfony\Component\HttpFoundation\Session\Storage\MetadataBag:private] => __metadata [storageKey:Symfony\Component\HttpFoundation\Session\Storage\MetadataBag:private] => _sf2_meta [meta:protected] => Array ( [u] => 1470214147 [c] => 1470208976 [l] => 0 ) [lastUsed:Symfony\Component\HttpFoundation\Session\Storage\MetadataBag:private] => 1470213715 [updateThreshold:Symfony\Component\HttpFoundation\Session\Storage\MetadataBag:private] => 0 ) ) [flashName:Symfony\Component\HttpFoundation\Session\Session:private] => flashes [attributeName:Symfony\Component\HttpFoundation\Session\Session:private] => attributes ) 1`
Thanks in advance!
$session->get('waiter')
returnsNULL
. Most likely because there is nothing under that key stored in the session or you've stored a literalNULL
there. – ShiraNai7