English 中文(简体)
• 如何阻止第2条从 Sym取第2条的后果?
原标题:How to stop Doctrine 2 from caching a result in Symfony 2?

我希望能够检索一个实体的现有版本,以便我能够将其与最新版本进行比较。 E.g. 编辑文件,我想知道,自在非行,价值是否发生了变化。

    $entityManager = $this->get( doctrine )->getEntityManager();
    $postManager = $this->get( synth_knowledge_share.manager );

    $repository = $entityManager->getRepository( KnowledgeShareBundle:Post );
    $post = $repository->findOneById(1); 

    var_dump($post->getTitle()); // This would output "My Title"
    $post->setTitle("Unpersisted new title");

    $existingPost = $repository->findOneById(1); // Retrieve the old entity

    var_dump($existingPost->getTitle()); // This would output "Unpersisted new title" instead of the expected "My Title"

是否有任何人知道我如何能够绕过这一ach子?

最佳回答

它是一种正常的行为。

理论在实体管理中记载了被检索的实体的参考资料,这样它就可以在不进行另一盘问的情况下归还一个实体。

你们可以做这样的事情:

$entityManager = $this->get( doctrine )->getEntityManager();
$repository = $entityManager->getRepository( KnowledgeShareBundle:Post );
$post = $repository->find(1);

$entityManager->detach($post);

// as the previously loaded post was detached, it loads a new one
$existingPost = $repository->find(1);

但意识到,由于邮政实体的美元贬值,如果你想再次坚持,你必须使用——和——合并——方法。

问题回答

You can also use the refresh method, which refreshes the persistent state of an entity from the database, overriding any local changes that have not yet been persisted. Something like:

$entityManager = $this->get( doctrine )->getEntityManager();
$repository = $entityManager->getRepository( KnowledgeShareBundle:Post );
$post = $repository->find(1);

$entityManager->refresh($post);

员额现在包含数据库的最后版本。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签