如何在 Symfony2 中使用 Doctrine OracleSessionInit 监听器? [英] How to use Doctrine OracleSessionInit listener with Symfony2?

查看:20
本文介绍了如何在 Symfony2 中使用 Doctrine OracleSessionInit 监听器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 oracle,但收到此错误:

I am using oracle and I am recieving this error:

无法将数据库值17-NOV-11 12.17.33 AM"转换为 Doctrine Type datetime.预期格式:Y-m-d H:i:s

Could not convert database value "17-NOV-11 12.17.33 AM" to Doctrine Type datetime. Expected format: Y-m-d H:i:s

我也无法创建新行,因为 oracle 抱怨日期时间格式.

Also I can´t create new rows because oracle complaints about the datetime format.

我知道mysql的日期时间格式和oracle的不一样.

I know that mysql datetime format and oracle one are different.

我知道您可以在 symfony 2 中使用教义监听器:

I understand that you can use doctrine listeners with symfony 2:

http://symfony.com/doc/current/cookbook/doctrine/event_listeners_subscribers.html

而且,创建了一个原则侦听器来解决此问题:

And, there´s a doctrine listener created to fix this issue:

Doctrine/DBAL/Event/Listeners/OracleSessionInit.php

Doctrine/DBAL/Event/Listeners/OracleSessionInit.php

问题是你到底是如何在 symfony 2 中打开它的.

The question is how Exactly your turn it on in symfony 2.

推荐答案

看来这次我会回答自己了.

Well It appears I will answer myself this time.

您必须使用事件标签将其添加为服务.

You have to add it as a service using the event tag.

app/config/config.yml 

services:
    my.listener:
        class: DoctrineDBALEventListenersOracleSessionInit 
        tags:
            - { name: doctrine.event_listener, event: postConnect }

my.listener 是监听器的任意名称.

my.listener is an arbitrary name for the listener.

这篇关于如何在 Symfony2 中使用 Doctrine OracleSessionInit 监听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆