symfony2 doctrine postConnect事件从未触发。

时间:2022-04-22 06:45:28

I am trying to use doctrine with an oracle 10g database in a symfony2 project.

我正在尝试用一个symfony2项目中的oracle 10g数据库来使用doctrine。

Everything is working fine but when I try to insert a row with a date column in a table I get the following error :

一切都很正常,但是当我尝试在表中插入一个日期列时,我得到了以下错误:

[PDOException] SQLSTATE[HY000]: General error: 1850 OCIStmtExecute: ORA-01850: ORA-01850: hour must be between 0 and 23 (ext\pdo_oci\oci_statement.c:148)

(PDOException) SQLSTATE[HY000]:一般错误:1850年OCIStmtExecute: ORA-01850: ORA-01850: hour必须在0到23之间(ext\pdo_oci\oci_statement.c:148)

According to How to use Doctrine OracleSessionInit listener with Symfony2? this error can be fixed by adding the Doctrine\DBAL\Event\Listeners\OracleSessionInit class to the Event Manager in Doctrine.

如何使用Symfony2来使用Doctrine OracleSessionInit ?这个错误可以通过在Doctrine中添加Doctrine\DBAL\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \

app/config/config.yml 

services:
    my.listener:
        class: Doctrine\DBAL\Event\Listeners\OracleSessionInit 
        tags:
            - { name: doctrine.event_listener, event: postConnect }

I tried this solution but it didn't work for me. So I manually added the listener to the eventManager in doctrine thgough my controller :

我试过这个办法,但它对我不起作用。因此,我在控制器中手动添加了监听器给eventManager:

public function indexAction()
    {
        $product= new Product();
        $product->setCreationDate(new \DateTime());
        $this->getDoctrine()->getConnection()->getEventManager()->addEventSubscriber($this->get('my.listener'));
        $em->persist($product);
        $em->flush();
        return array();
    }

This is working but this is not really elegant and I don't want to do that with all my controllers...

这是可行的,但这不是很优雅,我不想用我所有的控制器来做…

So my listener seems to be working properly. In my opinion, either the postConnect event is never triggered, or my config.yml is wrong and the listener is not properly set.

所以我的听众似乎工作正常。在我看来,postConnect事件不是触发的,也不是我的配置。yml是错误的,监听器没有正确设置。

Some help would be really appreciated.

有些帮助会非常感谢。

Thank you.

谢谢你!

1 个解决方案

#1


0  

Thank you m2mdas. I was able to debug the event manager with your advice and I figured out that my listener was not listed. So I checked my config.yml again and it turned out that it was not well formed (2 blank characters were lacking) .

谢谢你m2mdas。我可以用您的建议调试事件管理器,我发现我的监听器没有被列出。所以我检查了我的配置。yml再次证明,它并不是很好(2个空白字符)。

Anyway, everything is ok now, thank you very much for your help.

不管怎样,现在一切都好了,非常感谢你的帮助。

#1


0  

Thank you m2mdas. I was able to debug the event manager with your advice and I figured out that my listener was not listed. So I checked my config.yml again and it turned out that it was not well formed (2 blank characters were lacking) .

谢谢你m2mdas。我可以用您的建议调试事件管理器,我发现我的监听器没有被列出。所以我检查了我的配置。yml再次证明,它并不是很好(2个空白字符)。

Anyway, everything is ok now, thank you very much for your help.

不管怎样,现在一切都好了,非常感谢你的帮助。