[英]Symfony2 can't save to the database
I have a strange problem with saving to the database in Symfony2 controller. 我在Symfony2控制器中保存到数据库有一个奇怪的问题。 Here is the code:
这是代码:
$em = $this->getDoctrine()->getManager();
//$cars is taken from the entity and is not null
foreach($cars as $car) {
$car->setHasContent('yes');
$em->persist($car);
$em->flush();
}
I get the following error: 我收到以下错误:
Call to undefined method Symfony\Bundle\DoctrineBundle\Registry::getManager()
I can fix this by changing $em to: 我可以通过将$ em更改为:
$em = $this->get("doctrine.orm.entity_manager");
But then I get this error and don't know why (500 error): 但是然后我得到了这个错误,却不知道为什么(500错误):
ObjectManager does not support filters
Any ideas why? 有什么想法吗?
If it helps anyone there is Gedmo Doctrine Extension installed, and the error points to: 如果对任何人都有用,则说明已安装Gedmo Doctrine Extension,并且错误指出:
vendor/gedmo-doctrine-extensions/lib/Gedmo/Sluggable/SluggableListener.php at line 523
throw new \Gedmo\Exception\InvalidArgumentException("ObjectManager does not support filters");
I assume you are calling the manager from a controller, so I think you may have forgotten to make your class extends Controller. 我假设您正在从控制器中调用管理器,所以我认为您可能已经忘记使类扩展Controller。
class myClass extends Controller
{
// Your code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.