Php 代理原则中的对象而非实体
我在使用条令和符号,我面临一个问题。我得到的不是Php 代理原则中的对象而非实体,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,我在使用条令和符号,我面临一个问题。我得到的不是AppBundle\Entity\ItemProxies\uuuuucg\uuuuuuu\AppBundle\Entity\Item。所有数据均为空 $test = $em->getRepository(Entity\Item::class)->find(159); var_dump($test); exit; 我应该换什么 object(Proxies\__CG__\AppBundle\Entity\Item)[5348] pu
AppBundle\Entity\Item
Proxies\uuuuucg\uuuuuuu\AppBundle\Entity\Item。所有数据均为空
$test = $em->getRepository(Entity\Item::class)->find(159);
var_dump($test); exit;
我应该换什么
object(Proxies\__CG__\AppBundle\Entity\Item)[5348]
public '__initializer__' =>
object(Closure)[5237]
public '__cloner__' =>
object(Closure)[5802]
public '__isInitialized__' => boolean false
private 'id' (AppBundle\Entity\Item) => int 159
private 'name' (AppBundle\Entity\Item) => null
private 'slug' (AppBundle\Entity\Item) => null
private 'description' (AppBundle\Entity\Item) => null
private 'price' (AppBundle\Entity\Item) => null
private 'isFixedPrice' (AppBundle\Entity\Item) => null
private 'isExchangable' (AppBundle\Entity\Item) => null
private 'isDeliverable' (AppBundle\Entity\Item) => null
private 'totalViewsCount' (AppBundle\Entity\Item) => null
private 'condition' (AppBundle\Entity\Item) => null
private 'soldAt' (AppBundle\Entity\Item) => null
private 'category' (AppBundle\Entity\Item) => null
private 'user' (AppBundle\Entity\Item) => null
private 'attributes' (AppBundle\Entity\Item) => null
private 'pics' (AppBundle\Entity\Item) => null
protected 'createdAt' => null
protected 'updatedAt' => null
protected 'deletedAt' => null
我必须得到$test->getItem()->getSlug()。在数据库中存在具有此id的项。我找到了解决方案。以前的开发人员使用@Gedmo\SoftDeleteable(fieldName=“deletedAt”,timeAware=true)
因此,有些行删除了数据库中的_at值。这是他们不返回任何数据的一种方式。symfony进行延迟加载,这意味着,一旦您实际使用属于
Entity\Item
的属性,代理对象将返回实际对象的属性。@Jakumi关于延迟加载的说法是正确的,但您基本上是在测试$Item->getItem()。。。或者那是一个打字错误?@Cerad抱歉。打字错误我想得到$test->getSlug()。在数据库中,我有一个值“test”<代码>变量转储($test->getSlug());退出代码>`“错误消息”:“找不到id为(159)的'AppBundle\\Entity\\Item'类型的实体”`@Jakumi,我知道,但它不起作用。请参阅我上面的评论。在这种情况下,请检查您是否连接到了正确的数据库,如果是,请发布您的定义