如何扩展 Doctrine 2 来处理 CodeIgniter 2 中的 MySQL 空间(“点”字段类型)?
我正在使用 CodeIgniter 2 作为框架编写一个网站,最近我开始尝试使用 Doctrine 2 进行 ORM。
我的数据库需要存储空间数据(例如“点”类型的列),显然 Doctrine 无法立即处理该数据。
我在互联网上进行了搜索,只找到了这些提示: http://codeutopia.net/blog/2011/02/19/using-spatial-data-in-doctrine-2/
但那篇文章不清楚在哪里保存这些文件以及其他什么需要配置。我尝试联系作者,但从未收到回复。
有人可以帮忙吗?
谢谢! 瑞安
I'm coding a website using CodeIgniter 2 as my framework, and I recently started trying to use Doctrine 2 for ORM.
My database needs to store spatial data (e.g. a column of "point" type), and apparently Doctrine cannot handle that out of the box.
I have searched all over the internet and have only found these tips: http://codeutopia.net/blog/2011/02/19/using-spatial-data-in-doctrine-2/
But that article is unclear about where to save those files and what else needs to be configured. I tried contacting the author and never heard back.
Could someone please help?
Thanks!
Ryan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是很久以前的事了,所以我忘记了一些细节,但我把这 4 个文件放在一个名为 CodeIgniter/application/libraries/Doctrine/CustomAddon 的文件夹中:
我设置了命名空间每个为“CustomAddon”。
然后在 CodeIgniter/application/libraries/Doctrine.php 的底部我放置:
然后用法看起来像这样:
It was a long time ago so I've forgotten some details, but I put these 4 files in a folder called CodeIgniter/application/libraries/Doctrine/CustomAddon:
I set the namespace of each as "CustomAddon".
Then at the bottom of CodeIgniter/application/libraries/Doctrine.php I put:
Then usage looks something like this:
我使用的是原则 1.2,所以我不知道这是否适合你。使用 1.2.4,您可以在 yaml 或模型中声明点类型,它可以很好地转换到数据库。要将数据保存为点,您需要创建一个新的学说表达式,如下所示:
当然,使用您需要的数据而不是 25 和 10。根据原则 1.2.4,这可以正常工作并将数据保存在数据库中。要检索数据,您只需使用这种 select 语句:
您的对象中将有一个名为 point 的数组,其中包含两个元素(x 和 y)。正如我所说,我使用 1.2.4,但如果有一种简单的方法可以处理该版本中的点,则类似的方法必须与原则 2 一起工作。祝你好运!
I work with doctrine 1.2 so I don't know if this will work for you. With 1.2.4 you can declare a point type in your yaml or in your model and it translates fine to the database. To save data as a Point you need to create a new doctrine expression like this:
With the data you need instead those 25 and 10, of course. With doctrine 1.2.4 this will work fine and save the data in the DB. To retrieve your data you just have to use this kind of select statement:
And you will have an array called point with two elements (x and y) in your object. As i said, I work with 1.2.4 but if there is an easy way to work with points in that version something similar has to work with doctrine 2. Good luck!