Doctrine - 从表中删除数据

时间:2014-06-17 05:44:43

标签: symfony doctrine-orm doctrine

我有一个类,比如说CoreDoctrine.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

当我执行代码时,没有显示错误,但数据未从数据库中删除.... 我错过了什么吗?

更新:这里是insinstantiateEntities()函数:)

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;
    }

0 个答案:

没有答案