大佬教程收集整理的这篇文章主要介绍了Symfony 将表单与数据库进行比较,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如何将提交的表单字段与实际的数据库数据进行比较?
如果我使用我的存储库获取实体的副本,它实际上只是获取提交的表单的副本。我想知道表单中提交的数据是否从表单中发生了变化。
namespace App\ValIDator;
use Symfony\Component\ValIDator\ConsTraint;
use Symfony\Component\ValIDator\ConsTraintValIDator;
use Doctrine\ORM\EntitymanagerInterface;
use \App\Entity\Logistics\CarrIErSendle;
use Symfony\Component\Security\Core\Security;
class CarrIErDescUniqueValIDator extends ConsTraintValIDator {
/**
* @var Security
*/
private $security;
/**
* @var Em
*/
private $em;
public function __construct(EntitymanagerInterface $em,Security $security) {
$this->em = $em;
$this->security = $security;
}
public function valIDate($object,ConsTraint $consTraint) {
/* @var $consTraint \App\ValIDator\CarrIErDescUnique */
if (!$consTraint instanceof CarrIErDescUniquE) {
throw new UnexpectedTypeException($consTraint,CarrIErDescUnique::class);
}
if (null === $object->getDescription() || '' === $object->getDescription()) {
return;
}
$repoCurrent = $this->em->getRepository(CarrIErSendle::class)
->GetCurrentname($this->security->getUser(),$object->getSendlEID());
if ($object->getDescription() === $repoCurrent->getDescription()) {
return;
}
var_dump($object); var_dump($repoCurrent); dIE;
...
}
}
UnitOfWork() 是答案,在这里找到source
这将查询数据库,而不使用注入验证器的缓存版本。
$original = $this->em->getUnitOfWork()->getOriginalEntityData($object);
以上是大佬教程为你收集整理的Symfony 将表单与数据库进行比较全部内容,希望文章能够帮你解决Symfony 将表单与数据库进行比较所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。