【发布时间】:2015-04-20 16:33:02
【问题描述】:
我有一些奇怪的事情正在发生,我想知道它们是否与 PHP 或 Symfony 相关。基本上,从我的表单发出一个 ajax 请求并将表单数据发布到我的控制器。
现在我需要对刚刚保存到数据库的实体做一些工作,所以为了让它到达它需要去的地方,我有一个 EventListener 并且我做了
protected $alertEntity;
public function postPersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof AvailabilityAlert) {
$this->alertEntity = $entity;
}
}
public function postFlush(PostFlushEventArgs $args)
{
$this->api_service->addFlightsAction($this->alertEntity);
}
所以我在 postPersist 中获取实体,然后将其传递到 postFlush 中它需要去的地方。
这一切都很好,这里没有问题。奇怪的是这个
public function addFlightsAction($alert){
print_r($alert);
}
如果我在 print_r 中有上述内容,它将永远持续下去,直到最终导致错误分配大小溢出。
如果我在 var_dump 中执行上述操作,它会为我打印出警报,但它的格式不可读,例如(简短摘录)
<pre class='xdebug-var-dump' dir='ltr'>
<b>object</b>(<i>Ontro\AlertBundle\Entity\AvailabilityAlert</i>)[<i>284</i>]
<i>private</i> 'id' <font color='#888a85'>=></font> <small>int</small> <font color='#4e9a06'>39</font>
<i>private</i> 'searchCommand' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'A20APRLONLAX'</font> <i>(length=12)</i>
<i>private</i> 'isConnecting' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'no'</font> <i>(length=2)</i>
<i>private</i> 'lastUpdated' <font color='#888a85'>=></font>
<b>object</b>(<i>DateTime</i>)[<i>288</i>]
<i>public</i> 'date' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'2015-02-19 10:54:54'</font> <i>(length=19)</i>
<i>public</i> 'timezone_type' <font color='#888a85'>=></font> <small>int</small> <font color='#4e9a06'>3</font>
<i>public</i> 'timezone' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'Europe/London'</font> <i>(length=13)</i>
<i>private</i> 'isDeleted' <font color='#888a85'>=></font> <small>int</small> <font color='#4e9a06'>0</font>
<i>private</i> 'alertStatus' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'Active'</font> <i>(length=6)</i>
<i>private</i> 'bookingClass' <font color='#888a85'>=></font>
<b>object</b>(<i>Doctrine\ORM\PersistentCollection</i>)[<i>372</i>]
<i>private</i> 'snapshot' <font color='#888a85'>=></font>
那么它为什么要这样做呢?有什么办法可以很好地打印出来让我看到吗?我不介意上面的输出,只要它去掉了所有的 html 标签。
谢谢
【问题讨论】: