EntityManager#merge()期望参数1是实体对象,给定NULL。

时间:2016-08-03 09:04:41

标签: php session web doctrine-orm symfony

目前我正在完成计算机科学学位,我正在学习英语。

我有一个问题是从Symfony3中的会话对象中获取名为Waiter的实体。

    $em = $this->getDoctrine()->getManager();
    $session = $this->get('Session'); 
    $waiter = $em->merge($session->get('waiter'));
    return $this->render('default/waitermngr.html.twig',array('admin'=>$waiter));

此代码返回错误EntityManager#merge()期望参数1为实体对象,给定NULL。

但$ session对象不为null,因为return new Response ((string)print_r($session));返回:

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] =>数组([admin] => AppBundle \ Entity \ Waiter对象([idwaiter:protected] => 21 [loginwaiter:protected] =>管理员[passwdwaiter: protected] => 81dc9bdb52d04dc20036dbd8313ed055)))[flashes] => Symfony \ Component \ HttpFoundation \ Session \ Flash \ FlashBag Object([name:Symfony \ Component \ HttpFoundation \ Session \ Flash \ FlashBag:private] =>闪烁[闪烁:Symfony \ Component \ HttpFoundation \ Session \ Flash \ FlashBag:private] => Array()[storageKey:Symfony \ Component \ Ht tpFoundation \ Session \ Flash \ FlashBag:private] => _sf2_flashes))[已启动:受保护] => 1 [关闭:受保护] => [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] =>数组([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] =>闪烁[attributeName:Symfony \ Component \ HttpFoundation \ Session \ Session:private] =>属性)1`

提前致谢!

1 个答案:

答案 0 :(得分:0)

非常感谢ShiraNai7, 密钥存储名为'admin'而不是'服务员'

$session->set('admin',$waiter);

现在我得到了

$session->get('admin')