Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony2可以';t保存到数据库_Php_Symfony_Doctrine - Fatal编程技术网

Php Symfony2可以';t保存到数据库

Php Symfony2可以';t保存到数据库,php,symfony,doctrine,Php,Symfony,Doctrine,我在保存到Symfony2控制器中的数据库时遇到了一个奇怪的问题。代码如下: $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(); } 我得到

我在保存到Symfony2控制器中的数据库时遇到了一个奇怪的问题。代码如下:

$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();
}
我得到以下错误:

Call to undefined method Symfony\Bundle\DoctrineBundle\Registry::getManager()
我可以通过将$em更改为:

$em = $this->get("doctrine.orm.entity_manager");
但是我得到了这个错误,不知道为什么(500个错误):

你知道为什么吗

如果安装了Gedmo条令扩展,并且错误指向:

vendor/gedmo-doctrine-extensions/lib/Gedmo/Sluggable/SluggableListener.php at line 523
throw new \Gedmo\Exception\InvalidArgumentException("ObjectManager does not support filters");

我假设您是从控制器调用管理器,所以我认为您可能忘记了让类扩展控制器

class myClass extends Controller
{
    // Your code
}

如果他不扩展basecontroller,他怎么能调用函数get('myservice')?不,我扩展了控制器类Symfony 2/Doctrine 2的哪个版本?它非常神秘。我怀疑你可能有更多的代码在这里,你正在显示。请你能分享app/config/config.yml,正是你的输入。
class myClass extends Controller
{
    // Your code
}