Symfony 条令-从表中删除数据

Symfony 条令-从表中删除数据,symfony,doctrine-orm,doctrine,Symfony,Doctrine Orm,Doctrine,我有一个类,比如coreditor.php,其中有一个函数用于从表中删除记录,下面是代码 public function delete($entityManager, $objek){ $entityManager->remove($objek); $entityManager->flush(); $entityManager->clear(); echo "\n\n Data berhasil dihapus \

我有一个类,比如coreditor.php,其中有一个函数用于从表中删除记录,下面是代码

public function delete($entityManager, $objek){
        $entityManager->remove($objek);
        $entityManager->flush();
        $entityManager->clear();
        echo "\n\n Data berhasil dihapus \n\n";

    }
其中,$objek是我要删除的实体,$entityManager参数是从函数返回的Doctrine的entityManager的对象

然后我在index.php中像这样运行代码

$doctrine = new CoreDoctrine();
$em = $doctrine->instantiateEntities();  //this function returns the EntityManager object

$doctrine->delete($em, $luki);  //where $luki is the entity object
当我执行代码时,没有显示错误,但是数据没有从数据库中删除。。。。 我错过了什么吗

更新:以下是INSINSTATEEntities()函数:)


向我们显示
实例化项的代码
。还考虑使用SyfYNY2服务来注入<代码> EntItMeals;我已经更新了这个问题。我明白了,这就是实例化内容()。您自己实例化
EntityManager
有什么特别的原因吗?:)我的意思是,Symfony2是为你做的……是的,你为什么不从控制器调用,
$em=$this->getdoctor()->getManager()?嗯。。我只是想把所有的东西放在一个班级里。。。这样做是错误的吗?
public function instantiateEntities(){
        $paths = array(__DIR__."/src");
        $isDevMode = false;

        // the connection configuration
        $dbParams = array(
            'host' => '127.0.0.1',
            'driver'   => 'pdo_mysql',
            'user'     => 'root',
            'password' => '',
            'dbname'   => 'apbo2',
        );

        $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
        $entityManager = EntityManager::create($dbParams, $config);

        return $entityManager;
    }