Symfony2为控制器中的特定功能生成SQL日志

时间:2015-12-09 11:04:26

标签: php symfony logging

我有一些函数用于在我的Symfony2项目中插入和更新数据库表。对于那些函数,我想为正在执行的所有插入和更新查询生成详细的SQL日志。

我试图手动执行此操作,但我无法从持久且刷新的对象中获取SQL查询。

这是我的控制器功能:

private function pushChapterToCdpCodes($testObjectEntity, $testReleaseId) {

    $chapterTitle = $testObjectEntity->getTitle();
    $chapterNumber = $testObjectEntity->getNumber();
    $chapterOriginalId = $testObjectEntity->getOriginalId();
    // update chapter table

    if ($chapterOriginalId) {
        $chapter = $this->chapterRepository->findOneBy(array('id' => $chapterOriginalId));
    } else {
        $bookTitle = $testObjectEntity->getBook()->getTitle();
        $bookObject = $this->bookRepository->findOneBy(array('title' => $bookTitle));
        $bookId = $bookObject->getId();
        $bookPart = $testObjectEntity->getBookPart();
        $chapter = new \ICC\BookBundle\Entity\Chapter();

        if ($bookPart) {
            $bookPartOriginalNumber = $testObjectEntity->getBookPart()->getNumber();
            $bookPartOriginalTitle = $testObjectEntity->getBookPart()->getTitle();
            $originalBookPart = $this->bookPartRepository->findOneBy(array('number' => $bookPartOriginalNumber, 'title' => $bookPartOriginalTitle));
            $chapter->setBookPart($originalBookPart);
        } else {
            $chapter->setBook($this->bookRepository->findOneBy(array('id' => $bookId)));
        }
    }

    $chapter->setTitle($chapterTitle);
    $chapter->setNumber($chapterNumber);
    $chapter->setErrataReleaseId($testReleaseId);
    $this->cdpCodesEm->persist($chapter);
    $this->cdpCodesEm->flush();
}

我需要上面$this->cdpCodesEm->persist($chapter);结果的SQL日志。

请帮助我解决这个问题的正确方法。

0 个答案:

没有答案