我发现@ORM \ PrePersist在我的项目中不起作用,我想在持久保存之前转储一个数字然后终止该过程,但是问题是“ $ em-> persist();”仍然执行,并且号码没有转储,这是我的演示:
<?php
namespace Nlc\InformationBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
* @ORM\HasLifecycleCallbacks()
*/
class Adminuser
{
/**
* @ORM\PrePersist
*/
public function test(){
dump(1);die;
}
}
<?php
namespace Nlc\InformationBundle\Controller;
use Nlc\InformationBundle\Entity\Adminuser;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class AdminuserController extends Controller
{
/**
* @Route("/testadmin")
*/
public function testadmin(){
$em = $this->getDoctrine()->getManager();
$adminuser = new Adminuser();
$adminuser->setUsername('dave');
$adminuser->setPassword('123');
//before persist,I want dump 1 then die,but did't work
$em->persist($adminuser);
$em->flush();
return new Response();
}
}
答案 0 :(得分:0)
如果您尝试仅添加一个ID或类似的名称,Doctrine可能会尝试保留您的实体。
$ npm install --save url-regex