sko*_*ine 4 doctrine symfony doctrine-orm
我有这样的听众
use Doctrine\Common\EventSubscriber;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Doctrine\Common\Persistence\Event\PreUpdateEventArgs;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Events;
class MachineSubscriber implements EventSubscriber
Run Code Online (Sandbox Code Playgroud)
和方法
/**
* @param PreUpdateEventArgs $args
*/
public function preUpdate(PreUpdateEventArgs $args)
Run Code Online (Sandbox Code Playgroud)
和教义抛出异常
ContextErrorException:可捕获的致命错误:传递给 Certificate\MachineBundle\Event\MachineSubscriber::preUpdate() 的参数 1 必须是 Doctrine\Common\Persistence\Event\PreUpdateEventArgs 的实例,给定的 Doctrine\ORM\Event\PreUpdateEventArgs 实例,
这很奇怪,因为我使用了正确的课程。
您使用了错误的名称空间/类来键入preUpdate()
函数参数。正确的层次结构是:
Doctrine\Common\EventArgs
|_ Doctrine\ORM\Event\LifecycleEventArgs
|_ Doctrine\ORM\Event\PreUpdateEventArgs
Run Code Online (Sandbox Code Playgroud)
打字提示与...
use Doctrine\Common\EventArgs;
public function preUpdate(EventArgs $args)
{
// ...
Run Code Online (Sandbox Code Playgroud)
... 或者 ...
use Doctrine\ORM\Event\LifecycleEventArgs;
public function preUpdate(LifecycleEventArgs $args)
{
// ...
Run Code Online (Sandbox Code Playgroud)
... 或者 ...
use Doctrine\ORM\Event\PreUpdateEventArgs;
public function preUpdate(PreUpdateEventArgs $args)
{
// ...
Run Code Online (Sandbox Code Playgroud)
...但不包括:
use Doctrine\Common\Persistence\Event\PreUpdateEventArgs;
Run Code Online (Sandbox Code Playgroud)