我的VisitorController
班级
public function chooseVisitor($zone)
{
$em = $this->getDoctrine()->getManager();
$lvisitor = $em->getRepository('EMRSabaBundle:Personel')->findOneBy(array('status' => '1', 'lastv' => '1', 'zone' => $zone));
$id = $lvisitor->getId();
$lvisitor->setLastv(0);
$newvisitorid = $em->getRepository('EMRSabaBundle:Personel')->findNewVisitor($id);
$newvisitorid = $newvisitorid[0];
$newvisitor = $em->getRepository('EMRSabaBundle:Personel')->find($newvisitorid);
$newvisitor->setLastv(1);
$em->flush();
return $newvisitor;
}
public function defineZone($Customer)
{
$phone = substr($Customer,1);
switch ($phone)
{
case 2:
$zone = 1;
break;
case 4:
$zone = 1;
break;
case 8:
$zone = 2;
break;
case 7:
$zone = 3;
break;
}
return $zone;
}
我的EventListener
namespace EMR\SabaBundle\EventListener;
use Doctrine\ORM\Event\LifecycleEventArgs;
use EMR\SabaBundle\Entity\Orders;
use EMR\SabaBundle\Entity\Visit;
use EMR\SabaBundle\Controller\VisitController;
class EntityListener {
public function postPersist(LifecycleEventArgs $args)
{
$orders = $args->getEntity();
$em = $args->getEntityManager();
if ($orders instanceof Orders){
if ($orders->getStatus() == 1){
$VC = new VisitController();
$zone = $VC->defineZone($orders->getCustomer()->getId());
$personel = $VC->chooseVisitor($zone);
$visit = new Visit();
$visit->setDate(new \DateTime());
$visit->setStatus(0);
$visit->setOrders($orders);
$visit->setPersonel($personel);
$em->persist($visit);
$em->flush();
}
}
}
}
&安培;我的services.yml
entity.listener:
class: EMR\SabaBundle\EventListener\EntityListener
tags:
- { name: doctrine.event_listener, event: postPersist }
我想创造&当订单实体状态为1时,持续新访问 我不知道问题在哪里&如何调试事件监听器
任何人都可以帮我完成这项工作
答案 0 :(得分:0)
postUpdate,postRemove,postPersist
在EntityManager#flush()中调用三个post事件。变化 在这里与数据库中的持久性无关,但是你 可以使用这些事件来更改非可持久化项目,例如非映射项目 字段,日志记录甚至直接映射的关联类 教义。
尝试prePersist事件。